Maintain values inside loop
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Bora Eryilmaz
2022-12-12
编辑:Bora Eryilmaz
2022-12-12
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 个评论
Bora Eryilmaz
2022-12-12
编辑:Bora Eryilmaz
2022-12-12
Then, you can use a cell array to store the results. I've updated the code above.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!