How can I count the number of elements of a given value in a matrix?
이전 댓글 표시
I have a matrix such as.
44.147231 ; 24.358619
44.461415 ; 24.118248
44.258173 ; 23.185014
43.166729 ; 24.100443
43.159002 ; 26.708013
42.954059 ; 27.338612
44.139759 ; 23.927882
44.424679 ; 25.301393
42.957588 ; 25.530434
44.615223 ; 24.200719
44.384409 ; 25.486735
43.965701 ; 28.454219
43.400971 ; 21.492123
42.068687 ; 22.303336
43.245372 ; 28.932286
44.593751 ; 23.635179
The first column is longitude , the second column is latitude.
So, I want to count the number of region.
In the above matrix,

But I don't know how make the code.
Please help me...
채택된 답변
추가 답변 (3개)
Yona
2015년 3월 5일
0 개 추천
after this run double loop, one on latitude and the second on longitude, and by using length(find(A(:,1)==i & A(:,2)==j)) you will get the number of each combination.
puneet joshi
2015년 3월 5일
0 개 추천
well u can compare the complete matrix with the num u want to count .... and each time there is a match u can increase the count
Andrei Bobrov
2015년 3월 5일
편집: Andrei Bobrov
2015년 3월 5일
n = floor(min(a));
m = ceil(max(a));
[~,~,lo] = histcounts(a(:,1),n(1):m(1));
[~,~,la] = histcounts(a(:,2),n(2):m(2));
out = flip(accumarray([la,lo],1),1)
댓글 수: 2
Jos (10584)
2015년 3월 5일
Did you mean
[~, lo] = histc(..)
histc has been deprecated in R2014b. The replacement is histcounts which uses a different syntax and of course behaves slightly differently while still not solving all the issues of histc.
The syntax for histcounts is indeed the one Andrei used in his answer.
카테고리
도움말 센터 및 File Exchange에서 Lengths and Angles에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!