how to transfer complex valued matrix into excel
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
when i transfer my complex values into excel it takes 2 cells which creates confusion. Matrix size is 375x100.
1 Kommentar
Michael Haderlein
am 13 Aug. 2014
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.
Antworten (2)
Yu Jiang
am 13 Aug. 2014
Bearbeitet: Yu Jiang
am 13 Aug. 2014
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 Kommentare
braa
am 13 Dez. 2014
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 Kommentare
Ganesh P. Prajapat
am 25 Okt. 2015
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);
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!