フィルターのクリア

How to append for each iteration not using cells?

2 ビュー (過去 30 日間)
Maria Hart
Maria Hart 2021 年 1 月 21 日
編集済み: Stephen23 2021 年 1 月 21 日
Dear all,
the situation is the following: I have a projectlength of 3 years with an assumed number of hours of 10. For each hour the yield is calculated with a certain function (which I simplify in this example with the number 2). As the projectlength and hournumber should stay variable, I would like to first calculate the yield in each hour of the year (helper(k)) and then append the solutions of each projectyear below each other. So the yield should look like a simple 30x1 vector.
hournum = 10;
projectlength = 3;
yield = [];
for p=1:projectlength
for k = 1:hournum
helper(k)=2;
end
yield(p) = [yield(p); {helper(k)}];
end
Error Message: Index exceeds the number of array elements (0).

採用された回答

Stephen23
Stephen23 2021 年 1 月 21 日
編集済み: Stephen23 2021 年 1 月 21 日
Replace
yield(p) = [yield(p); {helper(k)}];
with
yield = [yield; helper(:)];

その他の回答 (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