在矩阵中以行为单位查找整数之间的列数(matlab)

时间:2016-07-19 18:37:46

标签: matlab matrix

我有一个愚蠢的问题,我无法找到^^的答案。

我有一个100x10000 double matrix containing integers from 1 to 4,希望找到row-wise column-count between every single integer

我的第一个想法是使用:

storage_ones = cell(100,1); 

     for n = 1:100; 
       [row col] = find(matrix(n,:)==1);
       storage_ones{n,1} = col;
     end

然后在另一个循环中减去它们。但是find我得到了以下答案:

  

空矩阵:1乘0

有人知道如何解决这个问题吗?

提前致谢!!

1 个答案:

答案 0 :(得分:0)

您的问题可能是由于以下两点之一:

  1. 由于您使用的是BlogPosting数据类型,因此您可能encountering floating point errors的值不会是<section> <article itemscope itemtype="http://schema.org/BlogPosting"></article> <article itemscope itemtype="http://schema.org/BlogPosting"></article> <article itemscope itemtype="http://schema.org/BlogPosting"></article> </section> < / em>的。如果是这种情况,请考虑不检查完全相等,而是使用小ε检查它是否非常接近1(这里我使用double)。

    1

    如果您确实拥有整数数据类型,请考虑使用1e-12来存储您的数据而不是[row, col] = find(abs(matrix(n,:) - 1) < 1e-12); ,然后您就可以执行精确的比较。

    uint8
  2. 您可能在该列中没有任何double。如果matrix = uint8(matrix); % Then for your comparison find(matrix(n,:) == 1) 找不到任何匹配项,则返回一个空数组。

    1