Search code examples
arraysmatlaboutputstore

Matlab, save output in array , loop


I want to create an array that can store the outputs each time that doing a loop. I think the problem is because in a every new iteration the numbers starts counting from the beginning so it stores only the last iteration! In each iteration the output is an array(7x3) so in total I have to have (28,3).But I tried a lot and i AM GETTING AN ARRAY (28,3) all with zeros except the last 7 rows. Thank you very much

You can see the code below:

 for t=1:ncell % in my case I have 4 cells
    ti=sort(T,2)              
    tt= sort(Cell{t}.ExBot,2)
    tq= sort(Cell{t}.ExTop,2)
    te= sort(Cell{t}.ExBT,2)
    %k=0
    z=0
    cc=[]
    %%%%% for exbottom
    I=ones(size(ti,1),1);
    for j=1:size(tt,1)
        for i=1:size(ti,1)
            if tt(j,:)==ti(i,:)
                k=k+1 ;
                %c(k,:)=[ti(j,:), ti(j+1,:)]
                I(i)=0;

                cc(k,:)=Y(i,:);
                cc(size(tt,1)+1,:)=cc(1,:)




            else
            end

        end


    end

end

Solution

  • Although more info would help as mentioned in the comments, from the information you've given, the problem is most likely in setting cc to empty when you start processing each cell.

    cc=[];
    

    On exiting the outermost loop you will only have results for the last iteration.

    On a related note you may want to use isequal or all for the comparison of vectors i.e. if isequal(tt(j,:),ti(i,:))