Thread Subject: use string to define input variables

Subject: use string to define input variables

From: Luca Cerone

Date: 20 Feb, 2008 11:24:02

Message: 1 of 2

Hi everybody,
I have a stucture STRUCT1 with fields:
field1,field2,field3

I have second structure STRUCT2 made in the following
way:

STRUCT2.field4.func=@function1;
STRUCT2.field4.variab={'field1','field2'};

STRUCT2 is used to mean that to obtain field4 in STRUCT1,
you have to apply function1, to the value stored in field1
and field2.

I would like to know if there is a way to automatically
computer STRUCT1.field4,
so that I can build a cycle, on all the derived values info
stored in STRUCT2.

I was thinking something like

A=fieldnames(STRUCT2)

for i=1:size(A,1)
STRUCT1.(A{i})=feval(STRUCT2.(A{i}).func,.....

But I can't understand how to pass argument values to the
feval statement.

I'm probably not thinking to the right approach for this
kind of problem,
so if you have any advice I would really appreciate it.

Thank you very much in advance,
Cheers -Luca-

Subject: use string to define input variables

From: Steven Lord

Date: 20 Feb, 2008 14:08:36

Message: 2 of 2


"Luca Cerone" <cerone@to-see.it> wrote in message
news:fph2ki$k71$1@fred.mathworks.com...
> Hi everybody,
> I have a stucture STRUCT1 with fields:
> field1,field2,field3
>
> I have second structure STRUCT2 made in the following
> way:
>
> STRUCT2.field4.func=@function1;
> STRUCT2.field4.variab={'field1','field2'};
>
> STRUCT2 is used to mean that to obtain field4 in STRUCT1,
> you have to apply function1, to the value stored in field1
> and field2.
>
> I would like to know if there is a way to automatically
> computer STRUCT1.field4,
> so that I can build a cycle, on all the derived values info
> stored in STRUCT2.
>
> I was thinking something like
>
> A=fieldnames(STRUCT2)
>
> for i=1:size(A,1)
> STRUCT1.(A{i})=feval(STRUCT2.(A{i}).func,.....
>
> But I can't understand how to pass argument values to the
> feval statement.

Look at the Remarks section of the FEVAL reference page for an example:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/feval.html

Alternately, you may be able to forego the FEVAL:

http://blogs.mathworks.com/loren/2006/01/11/mental-model-for-feval/

--
Steve Lord
slord@mathworks.com


Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
automatic operation Luca Cerone 20 Feb, 2008 06:24:58
struct Luca Cerone 20 Feb, 2008 06:24:58
automate Luca Cerone 20 Feb, 2008 06:24:57
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com