Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
write output to excel

Subject: write output to excel

From: maryam

Date: 19 May, 2010 09:49:04

Message: 1 of 8

Hi dears,
I am new member of mathgroups,my outputs in matlab are as complex numbers,I want to know how can I write them into an excel file.
Thanks
Maryam

Subject: write output to excel

From: Varun

Date: 19 May, 2010 10:02:05

Message: 2 of 8

"maryam " <maryam_tayefi@yahoo.com> wrote in message <ht0c6g$jqe$1@fred.mathworks.com>...
> Hi dears,
> I am new member of mathgroups,my outputs in matlab are as complex numbers,I want to know how can I write them into an excel file.
> Thanks
> Maryam

Hey,

store the complex numbers in a matrix and use the 'xlswrite' function.

Subject: write output to excel

From: maryam

Date: 19 May, 2010 10:30:26

Message: 3 of 8

"Varun " <var3161@yahoo.co.in> wrote in message <ht0cut$8n9$1@fred.mathworks.com>...
> "maryam " <maryam_tayefi@yahoo.com> wrote in message <ht0c6g$jqe$1@fred.mathworks.com>...
> > Hi dears,
> > I am new member of mathgroups,my outputs in matlab are as complex numbers,I want to know how can I write them into an excel file.
> > Thanks
> > Maryam
>
> Hey,
>
> store the complex numbers in a matrix and use the 'xlswrite' function.

Dear Varun,
Many thanks for your reply, I have already stored the data which are complex number in a matrix but xlswrite function writes the real unit in a excel file only and discards the imaginary unit. What can I do to solve this problem?

Thanks,
Maryam

Subject: write output to excel

From: TideMan

Date: 19 May, 2010 10:49:54

Message: 4 of 8

On May 19, 10:30 pm, "maryam " <maryam_tay...@yahoo.com> wrote:
> "Varun " <var3...@yahoo.co.in> wrote in message <ht0cut$8n...@fred.mathworks.com>...
> > "maryam " <maryam_tay...@yahoo.com> wrote in message <ht0c6g$jq...@fred.mathworks.com>...
> > > Hi dears,
> > > I am new member of mathgroups,my outputs in matlab are as complex numbers,I want to know how can I write them into an excel file.  
> > > Thanks
> > > Maryam
>
> > Hey,
>
> > store the complex numbers in a matrix and use the 'xlswrite' function.
>
> Dear Varun,
> Many thanks for your reply, I have already stored the data which are complex number in a matrix but xlswrite function writes the real unit in a excel file only and discards the imaginary unit. What can I do to solve this problem?
>
> Thanks,
> Maryam

I wasn't aware that Excel could handle complex numbers.
What version are you using?

Subject: write output to excel

From: Varun

Date: 19 May, 2010 11:16:07

Message: 5 of 8

"maryam " <maryam_tayefi@yahoo.com> wrote in message <ht0ek2$p0s$1@fred.mathworks.com>...
> "Varun " <var3161@yahoo.co.in> wrote in message <ht0cut$8n9$1@fred.mathworks.com>...
> > "maryam " <maryam_tayefi@yahoo.com> wrote in message <ht0c6g$jqe$1@fred.mathworks.com>...
> > > Hi dears,
> > > I am new member of mathgroups,my outputs in matlab are as complex numbers,I want to know how can I write them into an excel file.
> > > Thanks
> > > Maryam
> >
> > Hey,
> >
> > store the complex numbers in a matrix and use the 'xlswrite' function.
>
> Dear Varun,
> Many thanks for your reply, I have already stored the data which are complex number in a matrix but xlswrite function writes the real unit in a excel file only and discards the imaginary unit. What can I do to solve this problem?
>
> Thanks,
> Maryam

Hey Maryam,

just convert all the complex numbers in the matrix to string using 'num2str' and then use 'xlswrite'. I think that should work.

Regards,
Varun

Subject: write output to excel

From: ade77

Date: 19 May, 2010 15:47:04

Message: 6 of 8

"maryam " <maryam_tayefi@yahoo.com> wrote in message <ht0c6g$jqe$1@fred.mathworks.com>...
> Hi dears,
> I am new member of mathgroups,my outputs in matlab are as complex numbers,I want to know how can I write them into an excel file.
> Thanks
> Maryam

Simplest solution:

put the complex numbers into cell array, then use xlswrite.

Subject: write output to excel

From: tinne123

Date: 19 May, 2010 17:26:04

Message: 7 of 8

Hi maryam,

I have no idea on what your code is about, so maybe the following suggestion is not convenient to implement...

It's just an idea. How about creating for each of your complex numbers in Matlab separate matrices / arrays with its real and imaginary parts.

c = sqrt(-1)
c =

        0 + 1.0000i

rpart = real(c)

rpart =

     0
ipart = imag(c)

ipart =

     1

You may then write rpart and ipart into Excel by xlswrite. In Excel 2003 e.g. there is function =complex(real_num,i_num,suffix) that converts the two supplements into a complex number. From a practical point of view, I think this is cumbersome and you may need control over eventual complex numbers in your output. I would love to help you, but I am not strong enough in programming for that...

Good luck!

Subject: write output to excel

From: Saqib Ali

Date: 18 Nov, 2011 18:14:29

Message: 8 of 8

"maryam " <maryam_tayefi@yahoo.com> wrote in message <ht0c6g$jqe$1@fred.mathworks.com>...
> Hi dears,
> I am new member of mathgroups,my outputs in matlab are as complex numbers,I want to know how can I write them into an excel file.
> Thanks
> Maryam

Hi,

I had the same problem and there is a small piece of code for your help

Considering Cnoise, as a 2-D complex matrix . then the complex data can be written to excel using the following code

%%%%%%%%%%%%%

a=strcat('=COMPLEX(',num2str(real(Cnoise(:))),',',num2str(imag(Cnoise(:))),')');
b=mat2cell(a,ones(1,size(a,1)),size(a,2));
d=(reshape(b,size(Cnoise,1),size(Cnoise,2)));
xlswrite('Noise.xlsx',d,1); %Write Attenuation

%%%%%%%%%%%%%

It worked for me, I hope this helps you too.

Kind Regards
Dr. Saqib Ali

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us