Add the resulting array of each loop to a cell

前端 未结 2 834
礼貌的吻别
礼貌的吻别 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:42

    You can join your arrays either using horzcat or []. Then initialize an cell and save them into that cell.

    %% loop
    count = 0 ;
    iwant = cell([],1) ;
    while .....
            count = count+1 ;
        %% let be your arrays
        B1=1:9 ;
        B2=10:15 ;
        B3=16:19 ;
        B4=20:30 ;
        %% join them into array
        B = [B1 B2 B3 B4] ;
        iwant{count} = B ;
    end
    

提交回复
热议问题