How to index for saving an output of a for loop for each loop?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Wolfgang McCormack
el 13 de Mzo. de 2021
Comentada: Sergey Kasyanov
el 13 de Mzo. de 2021
Hi all, I have the following code and I want to save the output but how?
for i = 0.1:0.1:0.7
'Calculating somestuff here'
'S = output of modifications which is a 4 x 1 array'
'Now I want to wrtie the output to an array but I cannot use i because it's fractional'
Saved(:,i) = s 'but it does not work'
end
I tried this but no help:
for z = 1:100
for i = 0.1:0.1:0.7
'Calculating somestuff here'
'S = output of modifications which is a 4 x 1 array'
'Now I want to wrtie the output to an array but I cannot use i because it's fractional'
Saved(:,z) = s 'but it does not work'
end
end
I will definitely appreciate your help!
0 comentarios
Respuesta aceptada
Sergey Kasyanov
el 13 de Mzo. de 2021
Editada: Sergey Kasyanov
el 13 de Mzo. de 2021
Hello,
try that
I = 0.1:0.1:0.7;
Saved = zeros(4,length(I));
for i = 1:length(I)
'Calculating somestuff here'
'Use I(i) instead i'
Saved(:,i) = S;
end
2 comentarios
Sergey Kasyanov
el 13 de Mzo. de 2021
All problems can be solved in slow but working way
I = 0.1:0.1:0.7;
Saved = [];
for i = 1:length(I)
'Calculating somestuff here'
'Use I(i) instead i'
Saved = [Saved; S'];
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays 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!