Saving arrays in a For loop (3D array)

1 回表示 (過去 30 日間)
Tyler
Tyler 2016 年 4 月 14 日
コメント済み: Rik 2021 年 1 月 30 日
I am running a For loop where each loop outputs an m x n array. I would like to save these arrays into a 3D array, m x n x k, where k is the number of iterations on my loop. However, to keep my data accurate, I need to delete a certain number of rows from the beginning and end of each array, but the tricky part is that with each iteration my output array loses more rows than the previous iteration, so I have differently-sized arrays each time. Is there a way to store all of these together? My end goal is to plot them together on the same plot (some arrays will have more or less data points to plot than others). Or instead of deleting rows maybe I just make them nan value, and ignore the nan values when I plot it? In any case I don't want this to take up a whole lot of time, it seems like it should be simple. Any help would be appreciated, thank you!

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 14 日
編集済み: Azzi Abdelmalek 2016 年 4 月 14 日
Use a cell array to store your matrices
Example
for k=1:3
M{k}=rand(randi(10),3)
end
%To get your matrices
M{1}
M{2}
M{3}
  1 件のコメント
Rik
Rik 2021 年 1 月 30 日
Comment posted as flag by @Anil Kamat:
doesn't work
What do you mean by 'doesn't work'?

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

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