If statement indexing in a for loop
古いコメントを表示
I have made a for loop which models energy going being stored every hour. Three times a day energy is removed from storage. so far so good. I want to be able to check if the energy stored reaches a minimum value in the hour before energy is removed and if it does not then to add suffcient energy to reach the minimum value and record how much has been added. I'm trying to use an IF statement to interact with three columns in my matrix but am unable to make it work, it seems within the for loop my matrix becomes a vector? How can I isolate my three columns?
5 件のコメント
Cris LaPierre
2021 年 3 月 15 日
Share your code.
Calum Mackenzie
2021 年 3 月 15 日
Calum Mackenzie
2021 年 3 月 15 日
Calum Mackenzie
2021 年 3 月 15 日
Cris LaPierre
2021 年 3 月 15 日
Save your variables to a mat file and attache the mat file using the paperclip icon.
回答 (1 件)
Cris LaPierre
2021 年 3 月 15 日
0 投票
I would do this without a for loop.
- Compute min-columns 7,12,16
- Set any values <0 to 0 (you don't have to add to these rows to reach the minimum)
- Add the result to the previous hour (column?)
2 件のコメント
Calum Mackenzie
2021 年 3 月 16 日
Cris LaPierre
2021 年 3 月 16 日
Ok, so add it to columns (7:end) the first time, etc.
You are going to understand the problem better than any of us. We can only operate on the information you've shared.
カテゴリ
ヘルプ センター および 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!
