How to compare the first column of the rows to whole matrix?
이전 댓글 표시
I am trying to compare the first columns of rows to whole matrix, and try to find how many times each value occur in the matrix. For example, let
A = [2 4 6 1;
3 7 18 24;
4 2 6 0;
5 8 12 17;
6 2 4 0;
7 3 18 24];
I want to find how many times the row values [2 3 4 5 6 7] occur in the matrix. I can easily find it using for loop, but I don't want any loop. I am also not good at using arrayfun. Can somebody help me?
Thanks.
댓글 수: 1
José-Luis
2014년 10월 23일
The first column of rows?!?!
채택된 답변
추가 답변 (2개)
Roger Stafford
2014년 10월 24일
편집: Roger Stafford
2014년 10월 24일
C = sum(bsxfun(@eq,A(:,1),A),2)-1; % <-- Counts (not counting column 1)
댓글 수: 1
Andrei Bobrov
2014년 10월 24일
C = sum(bsxfun(@eq,A(:,1),reshape(A,1,[])),2);
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!