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 to Excel (column) rather than Range

Subject: Write to Excel (column) rather than Range

From: Alaa Elwany

Date: 2 Dec, 2011 20:00:09

Message: 1 of 6

Hi,

I have a Matlab code where I compute multiple vectors and need to write them to columns in Excel.

Is it possible to use:
 xlswrite(filename, M, range)
To write some array, x for example, in a column?

I do not know length(x) in advance, it gets computed within the m file. So, rather than exporting it to a range (B1:B10) for example, I would like to export it to Column B, no matter what it length would be.

Is this possible? I tried to set the range to 'B:B', but it didn't work.

Thanks in anticipation for your help.

Alaa

Subject: Write to Excel (column) rather than Range

From: ade77

Date: 2 Dec, 2011 20:17:08

Message: 2 of 6

to write only to column C , use 'C:C'.

Data = rand(100,1);
xlswrite('myfile.xlsx', Data, 'C:C');

Note: if u are using excel 2003 and below, use: myfile.xls

Subject: Write to Excel (column) rather than Range

From: Alaa Elwany

Date: 2 Dec, 2011 20:55:08

Message: 3 of 6

"ade77 " <ade100a@gmail.com> wrote in message <jbbbo4$oef$1@newscl01ah.mathworks.com>...
> to write only to column C , use 'C:C'.
>
> Data = rand(100,1);
> xlswrite('myfile.xlsx', Data, 'C:C');
>
> Note: if u are using excel 2003 and below, use: myfile.xls

Thanks a lot ade77. I already tried that. It works, but the only problem is that it exports Data to column C indeed, but then filss in ALL the remaining cells of column C with #N/A.

For example, if Data = rand(100,1), it adds random data in C1:C100, then #N/A in C101 onwards.

Any possible resolution to this?

thanks

Subject: Write to Excel (column) rather than Range

From: ade77

Date: 2 Dec, 2011 21:11:09

Message: 4 of 6

"Alaa Elwany" <alaa_elwany@yahoo.com> wrote in message <jbbdvc$2n6$1@newscl01ah.mathworks.com>...
> "ade77 " <ade100a@gmail.com> wrote in message <jbbbo4$oef$1@newscl01ah.mathworks.com>...
> > to write only to column C , use 'C:C'.
> >
> > Data = rand(100,1);
> > xlswrite('myfile.xlsx', Data, 'C:C');
> >
> > Note: if u are using excel 2003 and below, use: myfile.xls
>
> Thanks a lot ade77. I already tried that. It works, but the only problem is that it exports Data to column C indeed, but then filss in ALL the remaining cells of column C with #N/A.
>
> For example, if Data = rand(100,1), it adds random data in C1:C100, then #N/A in C101 onwards.
>
> Any possible resolution to this?
>
> thanks

sorry about that:
Data = rand(1000,1);
xlswrite('myfile4.xlsx', Data, ['C1:C' num2str(length(Data))]);

Subject: Write to Excel (column) rather than Range

From: ade77

Date: 2 Dec, 2011 21:18:08

Message: 5 of 6

of course if u know ahead the number of rows of the data, u can just pu it in:

data = rand(100,1);
xlswrite('myfile.xlsx, data, 'C1:C100');

Subject: Write to Excel (column) rather than Range

From: Alaa Elwany

Date: 4 Dec, 2011 23:45:08

Message: 6 of 6

"ade77 " <ade100a@gmail.com> wrote in message <jbbetc$6ac$1@newscl01ah.mathworks.com>...
> "Alaa Elwany" <alaa_elwany@yahoo.com> wrote in message <jbbdvc$2n6$1@newscl01ah.mathworks.com>...
> > "ade77 " <ade100a@gmail.com> wrote in message <jbbbo4$oef$1@newscl01ah.mathworks.com>...
> > > to write only to column C , use 'C:C'.
> > >
> > > Data = rand(100,1);
> > > xlswrite('myfile.xlsx', Data, 'C:C');
> > >
> > > Note: if u are using excel 2003 and below, use: myfile.xls
> >
> > Thanks a lot ade77. I already tried that. It works, but the only problem is that it exports Data to column C indeed, but then filss in ALL the remaining cells of column C with #N/A.
> >
> > For example, if Data = rand(100,1), it adds random data in C1:C100, then #N/A in C101 onwards.
> >
> > Any possible resolution to this?
> >
> > thanks
>
> sorry about that:
> Data = rand(1000,1);
> xlswrite('myfile4.xlsx', Data, ['C1:C' num2str(length(Data))]);


Thank you very much Ade! That worked just fine. Appreciate your help very much.

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