Add the resulting array of each loop to a cell

前端 未结 2 836
礼貌的吻别
礼貌的吻别 2021-01-28 11:21

I have some algorithm including a while loop:

 while  (condition)
    % do something and return a result array B
 end

Let\'s say:<

2条回答
  •  清歌不尽
    2021-01-28 11:55

    You can make use of the end keyword

    % 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
    

提交回复
热议问题