how to count non breaking ones from matrix?
Show older comments
hello sir/mam,i have a problem in counting non-breaking ones from this given matrix. can you suggest any algo or command to count that. result which i want is (2 2 5 4 2 4 4 2 2 2 2 2 2 2 2 2 3 4 2 4).

Accepted Answer
More Answers (1)
Andrei Bobrov
on 4 Dec 2015
t = [true(1,2);diff(A)~=0];
[m,n]=size(A);
[~,jj] = ndgrid(1:m,1:n);
ii = A.*cumsum(t.*A);
b = accumarray([ii(:)+1,jj(:)],1);
out = max(b(2:end,:));
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!