Loop to spit out consecutive values into excel

So I have a loop, that sifts through data, and every round of the loop, a new piece of data is calculated. I know with xlswrite I can put the data into an excel spreadsheet each time by specifying the sheet and cell, but every time I run the loop the new data will replace the old data. How do I make it so that the first time the loop runs it puts it in the first cell, and the second round it'll put it in next cell underneath it (and so on...)?
Thanks!

Antworten (1)

Sean de Wolski
Sean de Wolski am 6 Jul. 2011

0 Stimmen

The easiest way would just to keep a counter
count = 1;
for ii = 1:10;
%generate stuff
xlswrite(stuff,sprintf('A%i:A%i',count,count+length(stuff)));
count = count+length(stuff)+1;
end

3 Kommentare

Michael
Michael am 6 Jul. 2011
Thanks! I think this might be what I need, but I'm relatively unfamiliar with counters. Can you explain what the sprintf syntax signifies?
Sean de Wolski
Sean de Wolski am 6 Jul. 2011
Try running just this:
count = 1;
for ii = 1:10;
stuff = rand(ceil(rand*10),1);
sprintf('A%i:A%i',count,count+length(stuff))
count = count+length(stuff)+1;
end
stuff will be a vector somewhere between 1 and 10 elements long. The output from sprintf is telling it what cells to put it in A1:A2,A3:A11 etc..
Ashish Uthama
Ashish Uthama am 8 Jul. 2011
How large is your data? I would strongly recommend building up the cell array in the loop and then calling xlswrite just once after the loop.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 6 Jul. 2011

Community Treasure Hunt

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

Start Hunting!

Translated by