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).

 채택된 답변

Thorsten
Thorsten 2015년 12월 4일

0 개 추천

For a single column, use
diffcol = diff([0; col; 0]);
n = max(find(diffcol==-1)-find(diffcol==1));
Just loop over each column
for i = 1:size(A,2);
diffcol = [0; A(:,i); 0];
n(i) = max(find(diffcol==-1)-find(diffcol==1));
end

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2015년 12월 4일

0 개 추천

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,:));

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

질문:

2015년 12월 4일

답변:

2015년 12월 4일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by