how to transfer complex valued matrix into excel

조회 수: 13 (최근 30일)
saba
saba 2014년 8월 13일
댓글: Ganesh P. Prajapat 2015년 10월 25일
when i transfer my complex values into excel it takes 2 cells which creates confusion. Matrix size is 375x100.
  댓글 수: 1
Michael Haderlein
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
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

braa
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
Image Analyst
Image Analyst 2014년 12월 13일
Start a new question on this.
Ganesh P. Prajapat
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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by