代码之家  ›  专栏  ›  技术社区  ›  NLed

在matlab中,向单元格数组中的多行添加输入

  •  0
  • NLed  · 技术社区  · 16 年前

    我基本上想要一个数组,在ever循环中每行更新一个输入。 循环循环了30次,所以我想有30行和2列(x和y列)

    我有这个密码:

    For N=1:30
        .
        .
        .
        Binary = bwlabel(blacknwhite);
        s = regionprops(Binary,'centroid');
        centroids = cat(1, s.Centroid);
        hold(imgca,'on')
        plot(imgca,centroids(1,1), centroids(1,2),'r*')
        .
        .
        .
        end
    

    我不认为这是我想要的。。。在我的循环中只更新第一行。。 那么如何创建这个单元格数组呢?

    谢谢!

    2 回复  |  直到 16 年前
        1
  •  1
  •   Jonas    16 年前

    我假设你想存储质心。在这种情况下,您应该使用 centroids(N,:)=cat...

    centroids = zeros(30,2); %# this assumes 1 centroid per image. 
    For N=1:30
        .
        .
        .
        Binary = bwlabel(blacknwhite);
        s = regionprops(Binary,'centroid');
        centroids(N,:) = cat(1, s.Centroid);
        hold(imgca,'on')
        plot(imgca,centroids(N,1), centroids(N,2),'r*')
        .
        .
        .
    end
    
        2
  •  1
  •   High Performance Mark    16 年前

    已经很晚了,所以这不是一个完整的答案:

    1. 使用如下语句为整个数组预分配空间: newArray = zeros(N,2) .
    2. newArray(N,:) = newValues N .

    你是想建立一个细胞阵列还是阵列?