hi every one ,
조회 수: 1 (최근 30일)
이전 댓글 표시
A=[ 1 1 1 2 2 3 3 3 1 1 4 4 4 2 2 3 3 3 4 3 ]
how can i count the number of 1 and 2 and 3 and 4 in the row vector
thank u
댓글 수: 0
채택된 답변
Alex Mcaulley
2019년 5월 7일
sum(A==1) % or sum(A==2)...
댓글 수: 1
Adam Danz
2019년 5월 9일
편집: Adam Danz
2019년 5월 9일
Note that you'll need to calculate the unique values in A and then loop through each of them in order to use this method.
Aunq = unique(A);
count = zeros(size(Aunq));
for i = 1:length(Aunq)
count(i) = sum(A==Aunq(i)):
end
...which is all done in the one line of code I propsed using histcounts().
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Preprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!