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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by