xlswrite
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Ken Atwell
2012 年 3 月 23 日
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 件のコメント
Cynthia
2012 年 4 月 4 日
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
2012 年 4 月 4 日
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?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!