how can I save a variable to an excel file?

8 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2025-3-24
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 个评论
Sam Chak
Sam Chak 2025-3-24
@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 2025-3-24
@Sam Chak — My pleasure!
I had never gotten that sort of error, either. The segmentation approach seems the only way around it.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by