How to find 'numbers' of unique variable in matrix. How many quantity of variables.
조회 수: 3 (최근 30일)
이전 댓글 표시
x=[2 5 2 52 5 25 2 5 2 22 5 2 5 52 5 55 4 5 5 2 5 5 25 2 5 2 54 5 54 5 2 5 5 5 5 5 5 5 25 2 255 2 5 5 2 55 2 5 5 2 5 5 2 255 2 52 5 2 5 ];
unique(x)
ans =
Columns 1 through 6
2 4 5 22 25 52
Columns 7 through 9
54 55 255
How to find numbers using command. How many numbers of unique variable.
댓글 수: 0
채택된 답변
Konstantinos Sofos
2015년 10월 30일
Hi,
To reformulate your question (as I understood it) you would like to be able to return the count of occurrences of each element in a vector. There are multiple ways to do this. One solution would be by using hist and unique functions
x=[2 5 2 52 5 25 2 5 2 22 5 2 5 52 5 55 4 5 5 2 5 5 25 2 5 2 54 5 54 5 2 5 5 5 5 5 5 5 25 2 255 2 5 5 2 55 2 5 5 2 5 5 2 255 2 52 5 2 5 ];
>> [a,b]=hist(x,unique(x))
a =
17 1 28 1 3 3 2 2 2
b =
2 4 5 22 25 52 54 55 255
where a(i) is the (count) of b(i).
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!