Maintain values inside loop

3 vues (au cours des 30 derniers jours)
Ancalagon8
Ancalagon8 le 12 Déc 2022
Commenté : Ancalagon8 le 13 Déc 2022
I need help debugging this part of my code, from annual data i want to create 12 timetables , one for each month. Right now the result shows only the last month (December), without keeping the previous ones.
for i =1:12
resultsperMonth_=timetable(Datespermonth{i,1},dataperMonth{i,1})
end
Any ideas how to correct the above loop?

Réponse acceptée

Bora Eryilmaz
Bora Eryilmaz le 12 Déc 2022
Modifié(e) : Bora Eryilmaz le 12 Déc 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 commentaires
Bora Eryilmaz
Bora Eryilmaz le 12 Déc 2022
Modifié(e) : Bora Eryilmaz le 12 Déc 2022
Then, you can use a cell array to store the results. I've updated the code above.
Ancalagon8
Ancalagon8 le 13 Déc 2022
Thanks a lot!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by