how can I save a variable to an excel file?

8 visualizzazioni (ultimi 30 giorni)
Hi,
I have a complex variable (named "ST_normalized") in my MATLAB code. I want to save that file to an Excel file. Can you please help me with that? Thanks for your time.
regards

Risposta accettata

Star Strider
Star Strider il 24 Mar 2025
Try something like this —
ST_normalized = complex(randn(10,1), randn(10,1))
ST_normalized =
0.1199 + 0.4231i -0.1599 - 0.8992i 0.5147 - 2.1564i -1.0715 - 1.0423i -1.4185 - 1.3712i 0.0783 + 0.8757i 1.9040 - 1.2376i -1.2342 - 0.2979i -0.6224 - 0.7768i 1.6192 - 0.1821i
writematrix([real(ST_normalized), imag(ST_normalized)], 'Test1.xlsx')
Check = readmatrix('Test1.xlsx')
Check = 10×2
0.1199 0.4231 -0.1599 -0.8992 0.5147 -2.1564 -1.0715 -1.0423 -1.4185 -1.3712 0.0783 0.8757 1.9040 -1.2376 -1.2342 -0.2979 -0.6224 -0.7768 1.6192 -0.1821
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ST_normalized = complex(Check(:,1), Check(:,2))
ST_normalized =
0.1199 + 0.4231i -0.1599 - 0.8992i 0.5147 - 2.1564i -1.0715 - 1.0423i -1.4185 - 1.3712i 0.0783 + 0.8757i 1.9040 - 1.2376i -1.2342 - 0.2979i -0.6224 - 0.7768i 1.6192 - 0.1821i
.
  9 Commenti
Sam Chak
Sam Chak il 24 Mar 2025
@Star Strider, Thank you for demonstrating the segmentation approach. I have used the writematrix() function, although infrequently and not with datasets containing tens of thousands of entries. Therefore, this error is indeed new to me.
Error using writematrix (line 218)
The data block starting at cell 'A1' exceeds the sheet boundaries by 0 row(s) and 2199
column(s).
Star Strider
Star Strider il 24 Mar 2025
@Sam Chak — My pleasure!
I had never gotten that sort of error, either. The segmentation approach seems the only way around it.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Import from MATLAB in Help Center e File Exchange

Prodotti


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by