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

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

Konstantinos Sofos
Konstantinos Sofos am 30 Okt. 2015
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).

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by