Got Questions? Get Answers.
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:
use strmatch and cellfun

Subject: use strmatch and cellfun

From: Wendy

Date: 20 Jan, 2011 22:28:04

Message: 1 of 3

Hi all,

I have two arrays as following,

array1 = {'AA','EE'};
array2 = {'BB','AA','FF','CC','EE'};

I would like to match individual elements in array1 to array2, and return the index in array2. For instance, I would like to results be

ix = [2, 5];

I think that I need to use 'cellfun' and 'strmatch'. I tried following, but I am not sure what the error means. Could anybody give me some hints how to use 'cellfun' and 'strmatch' together? Thank you very much.

ix = cellfun(@(array1) strmatch(array1{1}, array2,'exact'), array2)

??? Cell contents reference from a non-cell array object.

Error in ==> NW_construction_CLCI>@(test1)strmatch(test1{1},test2,'exact')

Wendy

Subject: use strmatch and cellfun

From: Bruno Luong

Date: 20 Jan, 2011 22:39:05

Message: 2 of 3

"Wendy " <wlq121@gmail.com> wrote in message <ihactk$a27$1@fred.mathworks.com>...
> Hi all,
>
> I have two arrays as following,
>
> array1 = {'AA','EE'};
> array2 = {'BB','AA','FF','CC','EE'};
>
> I would like to match individual elements in array1 to array2, and return the index in array2. For instance, I would like to results be
>
> ix = [2, 5];
>

[~, idx]=ismember(array1, array2)

Bruno

Subject: use strmatch and cellfun

From: Matt Fig

Date: 20 Jan, 2011 22:49:05

Message: 3 of 3

Bruno has shown you the preferred method, but here is how one could do this will CELLFUN:

cellfun(@(x) strmatch(x,array2),array1)

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