Maintain values inside loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ancalagon8
am 12 Dez. 2022
Kommentiert: Ancalagon8
am 13 Dez. 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?
0 Kommentare
Akzeptierte Antwort
Bora Eryilmaz
am 12 Dez. 2022
Bearbeitet: Bora Eryilmaz
am 12 Dez. 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
3 Kommentare
Bora Eryilmaz
am 12 Dez. 2022
Bearbeitet: Bora Eryilmaz
am 12 Dez. 2022
Then, you can use a cell array to store the results. I've updated the code above.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!