how to count non breaking ones from matrix?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
AMIT BHASKAR
am 4 Dez. 2015
Beantwortet: Andrei Bobrov
am 4 Dez. 2015
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).
0 Kommentare
Akzeptierte Antwort
Thorsten
am 4 Dez. 2015
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
0 Kommentare
Weitere Antworten (1)
Andrei Bobrov
am 4 Dez. 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,:));
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!