How can I save a vector in a for loop to a pre-allocated cell if my first value of the loop (i) is not 1?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to save a vector for each iteration into a pre-allocated cell location---> sol = cell(1,10) ;
My for loop does not start at 1. It is:
for i = 20:5:60
Each time I try allocating this vector to the cell in the loop by using: sol{i} = results , it only saves the vector from the last iteration and leaves all the other cells empty.
Does anyone know how I can fix this to save results from each iteration into this cell? Thank you so much
0 comentarios
Respuestas (1)
Ameer Hamza
el 25 de Mayo de 2020
Editada: Ameer Hamza
el 25 de Mayo de 2020
Write the for-loop like this
x = 20:5:60;
for i = 1:numel(x)
% instead of i write x(i)
sol{i} = results;
end
10 comentarios
Ameer Hamza
el 25 de Mayo de 2020
Editada: Ameer Hamza
el 26 de Mayo de 2020
I am glad to be of help!
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!