Nested "For Loop" Array Size

5 ビュー (過去 30 日間)
IDN
IDN 2021 年 12 月 1 日
コメント済み: IDN 2021 年 12 月 1 日
How can i size my array to the output of a nested for loop? Thanks for the help!
DataArray = nan(300,1); % this is the array that i need to make sure is big enough to take in the data....
inputValsY3 = -20:20;
for y = 1:300
for y1 = 1:50
for y2 = 50:100
for y3 = 1:numel(inputValsY3)
[~,~,DataArray(y,y1,y2,y3)] = Function(Close,y,y1,y1,y2,y3);
end
end
end
end

採用された回答

James Tursa
James Tursa 2021 年 12 月 1 日
編集済み: James Tursa 2021 年 12 月 1 日
To keep the indexing the same, just use the top value from the loops. E.g.,
DataArray = nan(300,50,100,numel(inputValsY3));
Note that since your for-loop fills in the 3rd index starting at 50, there will be some NaN values left in the array after the loops are done. If you don't want that then you would have to shift the 3rd index down.
  1 件のコメント
IDN
IDN 2021 年 12 月 1 日
Thanks so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by