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:
find value in structure

Subject: find value in structure

From: Stefan

Date: 3 Apr, 2013 08:28:07

Message: 1 of 3

Hey Yall,

I want to find a value within a structure, i know I can find it with a for loop but that seems to be insufficient. Example:

The structure is called tree with field c containing the coordinates of an edge and c varies in length depending on the length of the edge! Value is a double and the value to find.

I cant figure out, how to do this with structfun

structfun(@find, tree.c, value) or
structfun(@x, find(value == x), tree.c)
does not work

Anyone a solution for my problem?

Thanks in advance!

Stefan

 

Subject: find value in structure

From: Loren Shure

Date: 3 Apr, 2013 10:27:21

Message: 2 of 3


"Stefan " <s.g.h.heinen@student.tue.nl> wrote in message
news:kjgp6n$4uo$1@newscl01ah.mathworks.com...
> Hey Yall,
>
> I want to find a value within a structure, i know I can find it with a for
> loop but that seems to be insufficient. Example:
>
> The structure is called tree with field c containing the coordinates of an
> edge and c varies in length depending on the length of the edge! Value is
> a double and the value to find.
>
> I cant figure out, how to do this with structfun
>
> structfun(@find, tree.c, value) or
> structfun(@x, find(value == x), tree.c) does not work
>
> Anyone a solution for my problem?
>
> Thanks in advance!
> Stefan
>
>


Be careful comparing floating point values. You probably want to look for a
value that has only a small difference from value - something like
find(abs(value-x) < tol) where tol depends on the magnitude of value
probably.

--
--Loren

http://blogs.mathworks.com/loren

Subject: find value in structure

From: kinor

Date: 3 Apr, 2013 11:29:07

Message: 3 of 3

"Stefan" wrote in message <kjgp6n$4uo$1@newscl01ah.mathworks.com>...
> Hey Yall,
>
> I want to find a value within a structure, i know I can find it with a for loop but that seems to be insufficient. Example:
>
> The structure is called tree with field c containing the coordinates of an edge and c varies in length depending on the length of the edge! Value is a double and the value to find.
>
> I cant figure out, how to do this with structfun
>
> structfun(@find, tree.c, value) or
> structfun(@x, find(value == x), tree.c)
> does not work
>
> Anyone a solution for my problem?
>
> Thanks in advance!
>
> Stefan

Hi Stefan,

read the help of structfun, it applies your function to each field of the structure
what about
find(abs(tree.c-val)<tol))
?

hth
kinor
>
>

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