how to transfer complex valued matrix into excel
16 ビュー (過去 30 日間)
古いコメントを表示
when i transfer my complex values into excel it takes 2 cells which creates confusion. Matrix size is 375x100.
1 件のコメント
Michael Haderlein
2014 年 8 月 13 日
As far as I know, Excel is not able to perform complex calculations (macros of course might be). Thus, you cannot put a complex value into one cell. So you need to decide if you split it into two matrices, imag and real, or if the absolute value is what you need or whatever. This strongly depends on your problem.
回答 (2 件)
Yu Jiang
2014 年 8 月 13 日
編集済み: Yu Jiang
2014 年 8 月 13 日
Hi Saba
I would like to suggest you place the complex numbers into the Excel sheet as strings. For example, the complex number 4 + 3i would be formed in an Excel cell as : ‘4+3i’
Now, in order to correctly write out the complex numbers from MATLAB to an Excel file you would have to format each complex number into a string. The first step in doing so is to convert the complex matrix to a numeric cell array using the num2cell function. Then use the cellfun function in conjunction with the num2str function handle to change the contents of the cell array to the string representations of the complex numbers. This final cell array is then passed to the XLSWRITE function to be written out to an Excel file.
Here is a piece of example code which performs this:
z = [2+3i 4+5i; 18+9i 1+17i];
c = num2cell(z);
towrite = cellfun(@num2str , c, 'UniformOutput', false);
xlswrite('testfile_new',towrite)
The complex numbers in the Excel sheet can be manipulated using functions available in the Analysis Toolpak. The Analysis Toolpak is an add-in for Excel available from Microsoft. Details on this can be found on the following page:
Hope it helps.
-Yu
0 件のコメント
braa
2014 年 12 月 13 日
hello Mr. Yu jang, your matrix (z) has all elements complex numbers
i have a matrix where some elements are complex and some aren't. i want to convert only those that are complex to cell then use the command cellfun. how can i do that avoiding a for loop (just to keep the code short)? if there is no other way than a for loop it's ok
2 件のコメント
Ganesh P. Prajapat
2015 年 10 月 25 日
you can use cell array to do it. For example:
a = 3 + 4i 5 - 4i 8+ 5i 2 - 7i 2+ 6i
a_str = num2str(a); a_cell = cellstr(a_str);
xlswrite('yourfile', a_cell);
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!