I need help debugging part of my code, from data i want to create timetables one for each class. Right now the result shows only the last class without keeping the previous ones.
Any ideas how to correct the loop?

 Respuesta aceptada

Bora Eryilmaz
Bora Eryilmaz el 12 de Dic. de 2022
Editada: Bora Eryilmaz el 12 de Dic. de 2022
Store the results in a vector of results instead of just keeping a scalar result for the last one. See the "{i}" index below:
for i = 1:12
resultsperMonth_{i} = timetable(Datespermonth{i,1},dataperMonth{i,1})
end
You can do something like this:
A = {};
for i = 1:5
A{i} = timetable;
end
A
A = 1×5 cell array
{0×0 timetable} {0×0 timetable} {0×0 timetable} {0×0 timetable} {0×0 timetable}

3 comentarios

Ancalagon8
Ancalagon8 el 12 de Dic. de 2022
Thanks for your reply. I have already tried this but I receive error: "Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts) is not supported. Use a row subscript and a variable subscript."
Bora Eryilmaz
Bora Eryilmaz el 12 de Dic. de 2022
Editada: Bora Eryilmaz el 12 de Dic. de 2022
Then, you can use a cell array to store the results. I've updated the code above.
Ancalagon8
Ancalagon8 el 13 de Dic. de 2022
Thanks a lot!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 12 de Dic. de 2022

Editada:

el 6 de En. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by