Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
strmatch always returns empty

Subject: strmatch always returns empty

From: Anne

Date: 20 Nov, 2009 15:08:44

Message: 1 of 3

Hi All,
As a newbee of Matlab, I apologize if this question sounds too
naive...

I have a cell array, ctrynames, of 24 country names, and another cell
array 'all_ctry' with 1875 country names in it. The classes are:

ctrynames <1*24> cell
all_ctry <1875*1> cell

Now I want to find where the countries in ctrynames lie in all_ctry. I
used this function

for i=1:24
indices=strmatch(ctrynames(i),all_ctry(:,1));
end

But indices always return empty. Would you please enlight me why is
that? Thank you very much

Subject: strmatch always returns empty

From: Jos

Date: 20 Nov, 2009 15:35:27

Message: 2 of 3

Anne <deutschlover@gmail.com> wrote in message <de12ec67-368f-4ea5-8ae7-510792f1e08e@l35g2000vba.googlegroups.com>...
> Hi All,
> As a newbee of Matlab, I apologize if this question sounds too
> naive...
>
> I have a cell array, ctrynames, of 24 country names, and another cell
> array 'all_ctry' with 1875 country names in it. The classes are:
>
> ctrynames <1*24> cell
> all_ctry <1875*1> cell
>
> Now I want to find where the countries in ctrynames lie in all_ctry. I
> used this function
>
> for i=1:24
> indices=strmatch(ctrynames(i),all_ctry(:,1));
> end
>
> But indices always return empty. Would you please enlight me why is
> that? Thank you very much

On each iteration of the for-loop you overwrite the previous result in "indices", like this

for i=1:3
   r1 = rand(i,1) ;
end
r1

whereas you might want

for i=1:3,
  r2{i} = rand(i,1) ;
end
r2

I suspect
strmatch(ctrynames(end),all_ctry(:,1))
to be empty ...

hth
Jos

Subject: strmatch always returns empty

From: Michael

Date: 20 Nov, 2009 16:46:07

Message: 3 of 3

>
> I have a cell array, ctrynames, of 24 country names, and another cell
> array 'all_ctry' with 1875 country names in it. The classes are:
>
>
> Now I want to find where the countries in ctrynames lie in all_ctry. I
> used this function
>


Hi Anne,

You could use "ismember". Suppose array "c_all" contains all city
names, and you want to know whether array "cs" contains a subset of
"c_all".

Example:

>> c_all={'c1','c2','c3','c4'}'
cs={'c2','c4'}

c_all =

    'c1'
    'c2'
    'c3'
    'c4'


cs =

    'c2' 'c4'

>> idx=ismember(c_all,cs)

idx =

     0
     1
     0
     1

>> c_all(idx)

ans =

    'c2'
    'c4'

"cs" contains two of the cities in "c_all".

Michael

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us