Maintain values inside loop

조회 수: 2 (최근 30일)
Ancalagon8
Ancalagon8 2022년 12월 12일
편집: Ancalagon8 2025년 1월 6일
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?

채택된 답변

Bora Eryilmaz
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
A = 1×5 cell array
{0×0 timetable} {0×0 timetable} {0×0 timetable} {0×0 timetable} {0×0 timetable}
  댓글 수: 3
Bora Eryilmaz
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.
Ancalagon8
Ancalagon8 2022년 12월 13일
Thanks a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by