how to transfer complex valued matrix into excel

18 visualizaciones (últimos 30 días)
saba
saba el 13 de Ag. de 2014
Comentada: Ganesh P. Prajapat el 25 de Oct. de 2015
when i transfer my complex values into excel it takes 2 cells which creates confusion. Matrix size is 375x100.
  1 comentario
Michael Haderlein
Michael Haderlein el 13 de Ag. de 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.

Iniciar sesión para comentar.

Respuestas (2)

Yu Jiang
Yu Jiang el 13 de Ag. de 2014
Editada: Yu Jiang el 13 de Ag. de 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

braa
braa el 13 de Dic. de 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 comentarios
Image Analyst
Image Analyst el 13 de Dic. de 2014
Start a new question on this.
Ganesh P. Prajapat
Ganesh P. Prajapat el 25 de Oct. de 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);

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by