How to store values from an array to another array using Loops

So the problem I have an Array A which contains around 200 elements, I get the elements of array A after doing calculations in a loop, that is for each iteration in the loop the array A gets stored with fresh 200 values. So I would like to store the 200 values in array A that I get in one iteration onto another array, say array B so that I do not lose the values after each iteration. That if I run the loop for around 10 times, I need my array B to have the 10 sets of 200 values from array A.
Any help would be appreciated

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 12 月 4 日
編集済み: Ameer Hamza 2020 年 12 月 4 日

1 投票

Most efficient option is to create a matrix and store each output in a column
B = zeros(200, 10)
for i = 1:10
% calculate A
B(:, i) = A;
end
Another flexible alternative is to create a cell array.
B = cell(1,10);
for i = 1:10
% calculate A
B{i} = A;
end

1 件のコメント

Maddy
Maddy 2022 年 2 月 27 日
This answer helped me too. Thanks a lot..

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2020b

質問済み:

2020 年 12 月 4 日

コメント済み:

2022 年 2 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by