Count specific values in a matrix and Find row and column number of the first value among consecutive same values.
3 views (last 30 days)
Show older comments
1) Counting the number of the specific values. such as
[1 1 1 1 1 1 2 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 6 6 6 6 6 7 7 7 8 8 8 8 8 ....]
=> result [ 6 4 5 ....]
2) Call the first row and column number of a specific value.
the first '2' value is [row column] = [1 7]
0 Comments
Accepted Answer
Andrei Bobrov
on 17 Nov 2015
Edited: Andrei Bobrov
on 17 Nov 2015
s = [1 1 1 1 1 1 2 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 6 6 6 6 6 7 7 7 8 8 8 8 8];
1)
t = [true,diff(s)~=0];
[ii,jj]=find(t);
result = diff([jj,numel(s)+1]);
2)
out = [s(t);ii;jj]';
0 Comments
More Answers (0)
See Also
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!