How do I count the number of each particular entry in a variable

I have a list of words stored as a variable on matlab and I need to be able to 'pickout' and count the different words. I know you can do that using the strfind function. However it is in a column not a row (Input strings must have one row.)So my question is how do you fix this, or is there a better way to pick out and out the words. An example of my problem
I have stored in my workspace the variable "countries"
val=
AUS
CAD
USA
USA
...
now i need to be able to count the number of each occurrence of the countries like 2 USA 1 AUS 1 CAD etc
Thanks

 Accepted Answer

2 Comments

hi i was just wondering how would i make my variable into an array. suppose i use
country=array('countries')
where "countries" is one of the stored variables it does not work.
thanks
country={'abc';'def';'ghi'} %to create a cell array
% to an element to your cell array
country{4}='jkl'

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!