xlswrite
1 次查看(过去 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!