MATLAB: Cycle counting from 0 succession 0 I have a matrix [ 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0] for exemple I'd like to have an outing: 2 x 4 "0" in succession 2 x 2 "0" in succession 1 x 3 "0" in succession How to program it Thank you. Best Answer >> M = [0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0];>> D = diff([false;M(:)==0;false]);>> L = find(D<0) - find(D>0);>> [U,~,X] = unique(L,'stable');>> V = histc(X,1:max(X));>> Z = [U(:),V(:)]Z = 5 2 6 1 4 1 Related SolutionsMATLAB: Search string array column for a specific string Have you tried ismember? You only need column 5, but you fed first argument of strcmp with the whole string array.rowIdx = find(ismember(X(:, 5), search)); % row indices of X which contain any of search elements MATLAB: I have a matrix like [1 0 0 1 0 1 0 ; 0 1 0 1 0 0 ; 1 0 0 1 1 1]. there are 3 rows and 7 column i wanna to see in the format like >> M = [1 0 0 1 0 1 ; 0 1 0 1 0 0 ; 1 0 0 1 1 1]M = 1 0 0 1 0 1 0 1 0 1 0 0 1 0 0 1 1 1>> S = size(M);>> [R,C] = ndgrid(1:S(1),1:S(2));>> sortrows([R(:),C(:),M(:)])ans = 1 1 1 1 2 0 1 3 0 1 4 1 1 5 0 1 6 1 2 1 0 2 2 1 2 3 0 2 4 1 2 5 0 2 6 0 3 1 1 3 2 0 3 3 0 3 4 1 3 5 1 3 6 1 Related QuestionHow to count the number of consecutive identical element of each row in a binary matrixNumber of times consecutive values occurArea from XY coordniatesSort the matrix according to order of columnFunction to solve a binary matrixNumber of times two numbers appear together
Best Answer