MATLAB: How to count zeros between not zero counting I want to count the number of zeros between 1 in each columns. 14X3 matrix So, results should be 3,2 in first column, 4 in second column and 2,3 in third column Please, help me. Best Answer vec = [0 1 0 0 0 1 0 0 1 0 0 0 0 0 ]' ;idx = find(vec==1) ;iwant = diff(idx)-1 Related SolutionsMATLAB: How to count the number of nonzero numbers in a row. Read about nnzA=[ 0 0 0 0 0.4 0 0 0.3; 0.1 0 0 0.7 0 0.2 0 0 ; 0 0 0.6 0 0 0 0 0.9] ;[m,n] = size(A) ;iwant = zeros(m,1) ; for i = 1:m iwant(i) = nnz(A(i,:)) ;endiwant MATLAB: Find the column with the least number of 1s (ones) in it | Find column with at least one non zero element count = sum(H);idx = find(count);[~, relidx] = min(count(idx)) ;mincol = idx(relidx); Related QuestionCounting zerosHow to count the number of zeros in a matrix until the value is non-zeroCounting zeros in arrayAdd column vector with for loopsCountCount the number of non-zero elements of a column/row of a 2D-MatrixCounting a groupe of zeros
Best Answer