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!