Thread Subject: eval begone! (part 2)

Subject: eval begone! (part 2)

From: jay vaughan

Date: 21 Apr, 2008 19:43:04

Message: 1 of 4

Hi Matlab folks,

I am continuing the process of purging eval statements from
my code, but got stuck on another one. Anybody know a way to
avoid eval here? A minimal version of my current code is below.

First, the user gives a file name. Then the name of the most
updated version of a particular routine (which I update
frequently) is returned by the function get_most_recent_func
which finds the name of the most recent .m file with the
base name given by func_basename in the directory func_path.
Finally the most recent function is called (for now using
eval) with FileName as the argument.

func_basename = 'my_func';
FileName = uigetfile;
func_name = get_most_recent_func(func_path, func_basename);
eval([func_name '(''' FileName ''')']);


Thanks,
J

Subject: eval begone! (part 2)

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 21 Apr, 2008 19:50:52

Message: 2 of 4

In article <fuiqo8$heq$1@fred.mathworks.com>,
jay vaughan <jvaughan5.nospam@gmail.com> wrote:
>I am continuing the process of purging eval statements from
>my code, but got stuck on another one.

>func_basename = 'my_func';
>FileName = uigetfile;
>func_name = get_most_recent_func(func_path, func_basename);
>eval([func_name '(''' FileName ''')']);

func_handle = str2func(func_name);
func_handle(FileName);
--
  "Is there any thing whereof it may be said, See, this is new? It hath
  been already of old time, which was before us." -- Ecclesiastes

Subject: eval begone! (part 2)

From: Yi Cao

Date: 21 Apr, 2008 20:02:02

Message: 3 of 4

"jay vaughan" <jvaughan5.nospam@gmail.com> wrote in message
<fuiqo8$heq$1@fred.mathworks.com>...
> Hi Matlab folks,
>
> I am continuing the process of purging eval statements
from
> my code, but got stuck on another one. Anybody know a way
to
> avoid eval here? A minimal version of my current code is
below.
>
> First, the user gives a file name. Then the name of the
most
> updated version of a particular routine (which I update
> frequently) is returned by the function
get_most_recent_func
> which finds the name of the most recent .m file with the
> base name given by func_basename in the directory
func_path.
> Finally the most recent function is called (for now using
> eval) with FileName as the argument.
>
> func_basename = 'my_func';
> FileName = uigetfile;
> func_name = get_most_recent_func(func_path,
func_basename);
> eval([func_name '(''' FileName ''')']);
>
>
> Thanks,
> J

Maybe you can use feval, something like

feval(func_name,FileName)

or

func = str2func(func_name);
func(FileName);

hth
Yi Cao

Subject: eval begone! (part 2)

From: jay vaughan

Date: 21 Apr, 2008 21:34:02

Message: 4 of 4

Thanks (again), Walter.

str2func did the trick very nicely and tipped me off on a
useful tool for the future.


J


roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fuir6s$r1r$1@canopus.cc.umanitoba.ca>...
> In article <fuiqo8$heq$1@fred.mathworks.com>,
> jay vaughan <jvaughan5.nospam@gmail.com> wrote:
> >I am continuing the process of purging eval statements from
> >my code, but got stuck on another one.
>
> >func_basename = 'my_func';
> >FileName = uigetfile;
> >func_name = get_most_recent_func(func_path, func_basename);
> >eval([func_name '(''' FileName ''')']);
>
> func_handle = str2func(func_name);
> func_handle(FileName);
> --
> "Is there any thing whereof it may be said, See, this is
new? It hath
> been already of old time, which was before us." --
Ecclesiastes

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
eval jay vaughan 21 Apr, 2008 15:45:09
rssFeed for this Thread

Contact us at files@mathworks.com