Saving data for each iteration in a for loop
Mostrar comentarios más antiguos
I am wanting to save the table data that is being written each loop, instead the data is being overwritten. I was going to try to do: info = [info output] that didn't work and I can't do info(i,:) = output because those deminsions do not line up. And the "table" varible I am not sure what I could do there to store all the data as oppsed to looping over it each time.
Thank you

Respuestas (2)
Yongjian Feng
el 13 de Ag. de 2021
1 voto
Your info needs to be initialized outside the loop, right?
4 comentarios
nathan stallworth
el 13 de Ag. de 2021
Yongjian Feng
el 13 de Ag. de 2021
I meant your info variable needs to be outside the loop. Something like thsi
info = [];
for i=1:9
info = [info output];
end
nathan stallworth
el 13 de Ag. de 2021
nathan stallworth
el 13 de Ag. de 2021
Cris LaPierre
el 13 de Ag. de 2021
Editada: Cris LaPierre
el 13 de Ag. de 2021
1 voto
You need to use indexing to assign the results of each loop to a new location. Look at this example on the for loop documentation page.
5 comentarios
nathan stallworth
el 13 de Ag. de 2021
Cris LaPierre
el 13 de Ag. de 2021
Cell arrays or structures could work.
You could also consider appending the new table to the existing one.
nathan stallworth
el 13 de Ag. de 2021
Cris LaPierre
el 13 de Ag. de 2021
Share the code (copy/paste. No one wants to transcribe from a screenshot) along with the complete error message (all the red text).
nathan stallworth
el 13 de Ag. de 2021
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!