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:
str2func help

Subject: str2func help

From: Aron Sceidt

Date: 6 Jun, 2011 13:49:04

Message: 1 of 5

a = 'length';
mystring = 'abc';
x = str2func(a);
rvar = 'mystring';
x(rvar)

Is it possible that in someway x(rvar) returns 3 instead of 8?

I know why is this happening but I want the last line to reference a variable with the name of what rvar stores. This would be declared already.

Help?

Subject: str2func help

From: Wayne King

Date: 6 Jun, 2011 15:07:04

Message: 2 of 5

"Aron Sceidt" <sigarru87@gmail.com> wrote in message <isilsg$4qv$1@newscl01ah.mathworks.com>...
> a = 'length';
> mystring = 'abc';
> x = str2func(a);
> rvar = 'mystring';
> x(rvar)
>
> Is it possible that in someway x(rvar) returns 3 instead of 8?
>
> I know why is this happening but I want the last line to reference a variable with the name of what rvar stores. This would be declared already.
>
> Help?

Hi, Why not just

a = 'length';
rvar = 'abc';
x = str2func(a);
x(rvar)

Wayne

Subject: str2func help

From: Aron Sceidt

Date: 6 Jun, 2011 15:23:20

Message: 3 of 5

"Wayne King" <wmkingty@gmail.com> wrote in message <isiqeo$l34$1@newscl01ah.mathworks.com>...
> "Aron Sceidt" <sigarru87@gmail.com> wrote in message <isilsg$4qv$1@newscl01ah.mathworks.com>...
> > a = 'length';
> > mystring = 'abc';
> > x = str2func(a);
> > rvar = 'mystring';
> > x(rvar)
> >
> > Is it possible that in someway x(rvar) returns 3 instead of 8?
> >
> > I know why is this happening but I want the last line to reference a variable with the name of what rvar stores. This would be declared already.
> >
> > Help?
>
> Hi, Why not just
>
> a = 'length';
> rvar = 'abc';
> x = str2func(a);
> x(rvar)
>
> Wayne

I wish it was that simple hehe.. The thing is that I'm reading the variable rvar from a database... I just gave this as an example here

Subject: str2func help

From: Wayne King

Date: 6 Jun, 2011 15:29:05

Message: 4 of 5

"Aron Sceidt" <sigarru87@gmail.com> wrote in message <isird8$o81$1@newscl01ah.mathworks.com>...
> "Wayne King" <wmkingty@gmail.com> wrote in message <isiqeo$l34$1@newscl01ah.mathworks.com>...
> > "Aron Sceidt" <sigarru87@gmail.com> wrote in message <isilsg$4qv$1@newscl01ah.mathworks.com>...
> > > a = 'length';
> > > mystring = 'abc';
> > > x = str2func(a);
> > > rvar = 'mystring';
> > > x(rvar)
> > >
> > > Is it possible that in someway x(rvar) returns 3 instead of 8?
> > >
> > > I know why is this happening but I want the last line to reference a variable with the name of what rvar stores. This would be declared already.
> > >
> > > Help?
> >
> > Hi, Why not just
> >
> > a = 'length';
> > rvar = 'abc';
> > x = str2func(a);
> > x(rvar)
> >
> > Wayne
>
> I wish it was that simple hehe.. The thing is that I'm reading the variable rvar from a database... I just gave this as an example here

But you're still reading it to the workspace as a string?

Subject: str2func help

From: Aron Sceidt

Date: 6 Jun, 2011 15:37:05

Message: 5 of 5

"Wayne King" <wmkingty@gmail.com> wrote in message <isiro1$p7i$1@newscl01ah.mathworks.com>...
> "Aron Sceidt" <sigarru87@gmail.com> wrote in message <isird8$o81$1@newscl01ah.mathworks.com>...
> > "Wayne King" <wmkingty@gmail.com> wrote in message <isiqeo$l34$1@newscl01ah.mathworks.com>...
> > > "Aron Sceidt" <sigarru87@gmail.com> wrote in message <isilsg$4qv$1@newscl01ah.mathworks.com>...
> > > > a = 'length';
> > > > mystring = 'abc';
> > > > x = str2func(a);
> > > > rvar = 'mystring';
> > > > x(rvar)
> > > >
> > > > Is it possible that in someway x(rvar) returns 3 instead of 8?
> > > >
> > > > I know why is this happening but I want the last line to reference a variable with the name of what rvar stores. This would be declared already.
> > > >
> > > > Help?
> > >
> > > Hi, Why not just
> > >
> > > a = 'length';
> > > rvar = 'abc';
> > > x = str2func(a);
> > > x(rvar)
> > >
> > > Wayne
> >
> > I wish it was that simple hehe.. The thing is that I'm reading the variable rvar from a database... I just gave this as an example here
>
> But you're still reading it to the workspace as a string?

yes, but the code is different from the one i gave here... basically my question here is how to achieve 3 without changing the first 4 lines?

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