Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!j39g2000yqn.googlegroups.com!not-for-mail
From: Xiaoxiao <xiaoxiaoyang@live.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to match string for cell array strmatch() in Matlab
Date: Wed, 3 Dec 2008 13:17:11 -0800 (PST)
Organization: http://groups.google.com
Lines: 53
Message-ID: <bfe4a0fb-0fcd-4df2-bb9b-678743c2e104@j39g2000yqn.googlegroups.com>
References: <e4c5e8e5-865e-44b8-b8a2-b2f19f8edb83@20g2000yqt.googlegroups.com> 
	<gh6s15$8gp$1@fred.mathworks.com>
NNTP-Posting-Host: 199.120.152.100
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1228339032 3672 127.0.0.1 (3 Dec 2008 21:17:12 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 3 Dec 2008 21:17:12 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: j39g2000yqn.googlegroups.com; posting-host=199.120.152.100; 
	posting-account=4XpXrwoAAADAXwqFgZzGOn1SmnxMe8pK
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; 
	InfoPath.1; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:504809


On Dec 3, 4:00=A0pm, "Stuart McGarrity"
<stuart.mcgarrity.nos...@mathworks.com> wrote:
> Xiaoxiao <xiaoxiaoy...@live.com> wrote in message <e4c5e8e5-865e-44b8-b8a=
2-b2f19f8ed...@20g2000yqt.googlegroups.com>...
> > Hi:
>
> > I have a string cell array like
>
> > v=3D{{'aaaa'}, {'bb'}, {'ccc'}, {'dd'}}
>
> > v =3D
>
> > =A0 =A0 {1x1 cell} =A0 =A0{1x1 cell} =A0 =A0{1x1 cell} =A0 =A0{1x1 cell=
}
>
> > and I would like to use strmatch() to located the cell array index in
> > which the string contains 'a' for example. I used below command:
>
> > =A0idx =3D strmatch('a', v)
> > ??? Error using =3D=3D> cell.strmatch at 18
> > Requires character array or cell array of strings as inputs.
>
> > K>> idx =3D strmatch('a', v(:))
> > ??? Error using =3D=3D> cell.strmatch at 18
> > Requires character array or cell array of strings as inputs.
>
> > =A0idx =3D strmatch('a', v{:})
> > ??? Error using =3D=3D> cell.strmatch
> > Too many input arguments.
>
> > I wrote v like above rather than v =3D {'aaa', 'bbb', 'cc', 'ddd'}
> > directly is because I got something like the original v above format
> > when I used textscan() function to read each line from a textfile and
> > then I need to parse the textscan results using the strmatch but met
> > same errors as I got above.
>
> > Any help wil be appreciated.
>
> You will probabaly need to use cellfun or a loop as you have the extra ce=
ll level. If you just want to know if there is an 'a' but don't care where =
in the string it is, you could use:
>
> >> cellfun(@(x) ~isempty(strfind(x{1},'a')),v)
>
> ans =3D
>
> =A0 =A0 =A01 =A0 =A0 0 =A0 =A0 0 =A0 =A0 0- Hide quoted text -
>
> - Show quoted text -

Thank you very much for the help, Stuart. It is very helpful. Here I
have one more question. Can you tell me why you need to use x{1}
instead of x directly in the strfind() function? Thanks again.