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

5 views (last 30 days)
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

Azzi Abdelmalek
Azzi Abdelmalek on 23 Mar 2013
  2 Comments
Jayden Deng
Jayden Deng on 24 Mar 2013
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
Azzi Abdelmalek
Azzi Abdelmalek on 24 Mar 2013
Edited: Azzi Abdelmalek on 24 Mar 2013
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

Find more on Model Import in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!