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:
Search a string in a specific field of an array of structures

Subject: Search a string in a specific field of an array of structures

From: pietro

Date: 4 Apr, 2014 20:16:08

Message: 1 of 3

Hi all,

how could I search a string in a specific field of an array of structures?

Here one example:

mystruct(1)=struct('a','abc','b','ade','c',' dbc')
mystruct(2)=struct('a','a31','b','ade','c',' d45')
mystruct(3)=struct('a','a4','b','4de','c',' d45')

mystring='de';
myfield='b';

result: [1 2]

Thanks

Subject: Search a string in a specific field of an array of structures

From: Bruno Luong

Date: 6 Apr, 2014 07:55:07

Message: 2 of 3

"pietro " <bracardi82@email.it> wrote in message <lhn3u8$bcm$1@newscl01ah.mathworks.com>...
> Hi all,
>
> how could I search a string in a specific field of an array of structures?
>
> Here one example:
>
> mystruct(1)=struct('a','abc','b','ade','c',' dbc')
> mystruct(2)=struct('a','a31','b','ade','c',' d45')
> mystruct(3)=struct('a','a4','b','4de','c',' d45')
>
> mystring='de';
> myfield='b';
>
> result: [1 2]
>
> Thanks

I don't know if mystring='de' is the typo, but here is an idea:

find(strcmp('ade',{mystruct.(myfield)}))

% Bruno

Subject: Search a string in a specific field of an array of structures

From: pietro

Date: 15 Apr, 2014 06:52:11

Message: 3 of 3

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <lhr18r$ps7$1@newscl01ah.mathworks.com>...
> "pietro " <bracardi82@email.it> wrote in message <lhn3u8$bcm$1@newscl01ah.mathworks.com>...
> > Hi all,
> >
> > how could I search a string in a specific field of an array of structures?
> >
> > Here one example:
> >
> > mystruct(1)=struct('a','abc','b','ade','c',' dbc')
> > mystruct(2)=struct('a','a31','b','ade','c',' d45')
> > mystruct(3)=struct('a','a4','b','4de','c',' d45')
> >
> > mystring='de';
> > myfield='b';
> >
> > result: [1 2]
> >
> > Thanks
>
> I don't know if mystring='de' is the typo, but here is an idea:
>
> find(strcmp('ade',{mystruct.(myfield)}))
>
> % Bruno

Thanks Bruno, it works...

cheers

Pietro

Tags for 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