Borrar filtros
Borrar filtros

xlswrite

2 visualizaciones (últimos 30 días)
Nasir Qazi
Nasir Qazi el 23 de Mzo. de 2012
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 ..

Respuesta aceptada

Ken Atwell
Ken Atwell el 23 de Mzo. de 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 comentarios
Cynthia
Cynthia el 4 de Abr. de 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
Ken Atwell el 4 de Abr. de 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?

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by