简体   繁体   English

Matlab,将输出保存在array中,循环

[英]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. 在每次迭代中,输出是一个array(7x3)所以我总共必须有(28,3) 。但是我做了很多尝试,我得到了一个ARRAY (28,3) ,除了最后7行外,其他所有零。 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

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设置为空。

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 ie if isequal(tt(j,:),ti(i,:)) 在相关说明中,您可能需要使用isequalall用于向量比较,即if isequal(tt(j,:),ti(i,:))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM