フィルターのクリア

Concatenate unequal sized arrays produced in a loop

1 回表示 (過去 30 日間)
SMA
SMA 2015 年 11 月 9 日
コメント済み: Star Strider 2019 年 6 月 11 日
I have a for loop (d = 1:57) for which I am trying to save the results in a single matrix, however each iteration produces a different length of array (e.g 1x58 single, 1x46 single, 1x59 single, ...). It is not possible to know the length of the longest array produced since I'll be running the same loop with various inputs and keeping track of the lengths will be tedious. How can I concatenate the arrays produced from the loop into one matrix perhaps by adding NaNs to the shorter arrays. Some suggested storing the vectors in matrix as result(d,:) which of course gives an error.
Result should have the dimension (57xlength of longest array).

採用された回答

Star Strider
Star Strider 2015 年 11 月 9 日
I would use a Cell Array.
for d = 1:57
A{d} = ...
end
Notice the use of curly brackets ‘{}’ to denote the cell array elements.
  10 件のコメント
jay yawson
jay yawson 2019 年 6 月 11 日
I found this helpful.. thank you
Star Strider
Star Strider 2019 年 6 月 11 日
My pleasure.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by