I have a column with the following data:
Size: 100x7
val =
USA
USA
France
USA
France
I want to show the data on pie chart. to do this, I need to know how much USA occur in this column, and so on.
I read about the functions unique,accumarray but I dont success
I would like to get some suggestions how to do that.
Thanks.
This will give you the number of occurrences by using regexp:
The two output variables are now
Use the third output of
unique
, and make sure that those input strings are in acell
array. The third output ofunique
is pretty cool, because it assigns a unique ID for each unique quantity that is seen in the input. As such, if you had a sequence of characters froma
toe
, it would assign a unique ID for each unique character that it has found, between 1 and 5. Also, the first output ofunique
gives you an array that only contains the unique quantities seen in the input.You can then use
accumarray
on this third output to count how many times you see a particular country over all countries listed.I get:
Also for
countries
:Notice that each element of
counts
corresponds to how many times you see that particular country in the same position as the country incountries
, so France is seen 2 times, and USA 3 times.If you have the statistics toolbox, you can also do the following:
You can use
unique
withhistc
-You can then display the number of occurrences against the country names as a table -
Display output as a pie chart -