将每个循环的结果数组添加到单元格 [英] Add the resulting array of each loop to a cell
本文介绍了将每个循环的结果数组添加到单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些算法,其中包括 while
循环:
I have some algorithm including a while
loop:
while (condition)
% do something and return a result array B
end
让我们说:
-Loop 1: B1=[1 2 3 4 5....9];
-Loop 2: B2=[10 11 12....15];
-Loop 3: B3=[16 17 18 19] ;
-Loop 4: B4=[20 21 22....30];
循环完成后,如何创建单元格 A = {B1,B2,B3,B4}
?
How can I create a cell A={B1,B2,B3,B4}
when the loop is finished?
对于我的真实数据, while
循环可能循环100次或更多,以上只是一种简化.
For my real data, the while
loop may be looping 100 times or more, the above is a simplification.
推荐答案
您可以使用 end
关键字
% Initialise empty cell array
A = {};
while *condition*
% Create B using some calculation (different each loop)
B = [1 2 3];
% Other code ...
% Assign to array
A{end+1} = B;
end
这篇关于将每个循环的结果数组添加到单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文