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!