How to find 'numbers' of unique variable in matrix. How many quantity of variables.

2 次查看(过去 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.

采纳的回答

Konstantinos Sofos
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 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by