xlswrite
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a Program where a values of 'A' is changing in each iteration and I want to save each value separately in excel so later I can make a graph, I am using xlswrite but it overwrite the previous value which I don't want them to change , how can I do that ..
0 Commenti
Risposta accettata
Ken Atwell
il 23 Mar 2012
Hi Nasir,
Is the value of A a scalar? Even if you could make this work, writing to an Excel file at every loop iteration sounds like slow going. How about preserving the values of A within MATLAB itself:
allA = zeros(numLoopIterations, 1);
for i=1:numLoopIterations
A = ...
allA(i) = A;
end
plot(allA)
I've pre-allocated above for performance reasons, but I suspect even not pre-allocating (if numLoopIternations is not known, for example) will be much faster than writing to Excel:
allA = [];
while ...
A = ...
allA(end+1) = A;
end
plot(allA)
2 Commenti
Cynthia
il 4 Apr 2012
This answer was very helpful, but how do you do this if A is a vector, not a scalar? I'm not plotting the data but I'm exporting it into MS Excel. The last iteration keeps getting written over just like Nasir's plot was written over.
Ken Atwell
il 4 Apr 2012
In the vector case, if A is always the same length, it is only incrementally more complicated. You can create a 2-D matrix, with each row representing one "column" of A:
allA = zeros(numLoopIterations, lengthOfVectorfA);
for i=1:numLoopIterations
A = ...
allA(i,:) = A;
end
If A is not the same length in each iteration (i.e., your matrix/spreadsheet will be ragged right), you will need to use a cell array or some such to record vectors of varying lengths. Is this the case for you, Cynthia?
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!