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:
Writing to excel cells

Subject: Writing to excel cells

From: Leyo Joseph

Date: 31 Jan, 2013 12:15:11

Message: 1 of 4

I am looking for a method to write data to various cells of Excel sheet using a for loop.
for example ==>
data =[1 2 3 4 5];
xlswrite('F:\Test Data\example.xlsx',menu,'data','a2');
above writes contents of "data" to cell a2.
Is there a way to wirite contents of data to various cells using a for loop.
Like data(1) to cell(1,1) of excel.
data(2) to cells(1,3)
data(3) to cells(1,5)....

Subject: Writing to excel cells

From: dpb

Date: 31 Jan, 2013 15:09:36

Message: 2 of 4

On 1/31/2013 6:15 AM, Leyo Joseph wrote:
> I am looking for a method to write data to various cells of Excel sheet
> using a for loop.
> for example ==>
> data =[1 2 3 4 5];
> xlswrite('F:\Test Data\example.xlsx',menu,'data','a2');
> above writes contents of "data" to cell a2.
> Is there a way to wirite contents of data to various cells using a for
> loop.
> Like data(1) to cell(1,1) of excel.
> data(2) to cells(1,3)
> data(3) to cells(1,5)....

Use num2str() or sprintf() etc. create a dynamic cell address...

fn=fullfile('F:','Test Data', 'example.xlsx');
for i=1:length(data)
   c=['a' num2str(2*i-1)];
   xlswrite(fn,'data',c);
end

Obviously you can create more generic cell addresses by using character
variables for columns as well...

--

Subject: Writing to excel cells

From: Leyo Joseph

Date: 31 Jan, 2013 16:11:08

Message: 3 of 4

dpb <none@non.net> wrote in message <kee1ed$q0j$1@speranza.aioe.org>...
> On 1/31/2013 6:15 AM, Leyo Joseph wrote:
> > I am looking for a method to write data to various cells of Excel sheet
> > using a for loop.
> > for example ==>
> > data =[1 2 3 4 5];
> > xlswrite('F:\Test Data\example.xlsx',menu,'data','a2');
> > above writes contents of "data" to cell a2.
> > Is there a way to wirite contents of data to various cells using a for
> > loop.
> > Like data(1) to cell(1,1) of excel.
> > data(2) to cells(1,3)
> > data(3) to cells(1,5)....
>
> Use num2str() or sprintf() etc. create a dynamic cell address...
>
> fn=fullfile('F:','Test Data', 'example.xlsx');
> for i=1:length(data)
> c=['a' num2str(2*i-1)];
> xlswrite(fn,'data',c);
> end
>
> Obviously you can create more generic cell addresses by using character
> variables for columns as well...
>
> --Hello,
Thanks. It is working fine. See my code below==>
data =[1 2 3 4 5];
%xlswrite('F:\Test Data\example.xlsx',data,'meas','a2');
for i=1:length(data)
   c=['a' num2str(2*i-1)];
   xlswrite('F:\Test Data\example.xlsx',data(i),'meas',c);
end

Now I want to try this to write to various column.
Like data(1) to A5,
data(2) to B5
data(3) to C5
 As you mentioned above, it is possible to do this. If you don't mind, please give me a simple example.
>

Subject: Writing to excel cells

From: dpb

Date: 31 Jan, 2013 17:47:49

Message: 4 of 4

On 1/31/2013 10:11 AM, Leyo Joseph wrote:
...

> Now I want to try this to write to various column.
> Like data(1) to A5,
> data(2) to B5
> data(3) to C5
> As you mentioned above, it is possible to do this. If you don't mind,
> please give me a simple example.

Well, where's your sense of adventure/exploration/learning...???

for i='A':'Z',disp([i num2str(5)]);end

--

Tags for this Thread

No tags are associated with 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