Thread Subject: running an .m file

Subject: running an .m file

From: Teodor

Date: 11 Mar, 2010 07:48:09

Message: 1 of 6

Hello! Can anyone help me with something?
My problem is that I have to run some functions from my directory without typing:
 run function_name.m
For example I have a list in excel with all the functions that are in my directory and I made a code in matlab that reads the excel file and puts all the functions in an array.
Then for the array{1,1} I will have a variable='function_name' that I will want to run.
How can I say: run variable in matlab and the function_name from my directory corresponding to the variable=function_name will run?
Ex:
I have in my directory test.m
var = 'test'

run var -> this will not work

Help please!
Thanks in advance!
Alexandra

Subject: running an .m file

From: James Tursa

Date: 11 Mar, 2010 07:55:25

Message: 2 of 6

"Teodor " <teodoralexandra@yahoo.com> wrote in message <hna77p$bqc$1@fred.mathworks.com>...
> Hello! Can anyone help me with something?
> My problem is that I have to run some functions from my directory without typing:
> run function_name.m
> For example I have a list in excel with all the functions that are in my directory and I made a code in matlab that reads the excel file and puts all the functions in an array.
> Then for the array{1,1} I will have a variable='function_name' that I will want to run.
> How can I say: run variable in matlab and the function_name from my directory corresponding to the variable=function_name will run?
> Ex:
> I have in my directory test.m
> var = 'test'
>
> run var -> this will not work
>
> Help please!
> Thanks in advance!
> Alexandra

doc eval

James Tursa

Subject: running an .m file

From: Walter Roberson

Date: 11 Mar, 2010 07:59:17

Message: 3 of 6

Teodor wrote:

> I have in my directory test.m
> var = 'test'
>
> run var -> this will not work

run(var)

Subject: running an .m file

From: Teodor

Date: 11 Mar, 2010 08:32:20

Message: 4 of 6

Walter Roberson <roberson@hushmail.com> wrote in message <hna7sl$jqd$3@canopus.cc.umanitoba.ca>...
> Teodor wrote:
>
> > I have in my directory test.m
> > var = 'test'
> >
> > run var -> this will not work
>
> run(var)

I have tryoed to put this command, but it doesn't work, it gives an error that it cannot find the function_name.m....but I have it in my working directory....

Subject: running an .m file

From: Pekka Kumpulainen

Date: 11 Mar, 2010 10:52:06

Message: 5 of 6

"Teodor " <teodoralexandra@yahoo.com> wrote in message <hna9qk$sj8$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <hna7sl$jqd$3@canopus.cc.umanitoba.ca>...
> > Teodor wrote:
> >
> > > I have in my directory test.m
> > > var = 'test'
> > >
> > > run var -> this will not work
> >
> > run(var)
>
> I have tryoed to put this command, but it doesn't work, it gives an error that it cannot find the function_name.m....but I have it in my working directory....

If your var = 'test';
Both eval(var) and run(var) should work. They work here.
If var = 'test.m', they don't work.

Are you sure your MATLAB is in the directory you think?
Try which(var) or which test.

Subject: running an .m file

From: Teodor

Date: 11 Mar, 2010 12:00:26

Message: 6 of 6

"Teodor " <teodoralexandra@yahoo.com> wrote in message <hna9qk$sj8$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <hna7sl$jqd$3@canopus.cc.umanitoba.ca>...
> > Teodor wrote:
> >
> > > I have in my directory test.m
> > > var = 'test'
> > >
> > > run var -> this will not work
> >
> > run(var)
>
> I have tryoed to put this command, but it doesn't work, it gives an error that it cannot find the function_name.m....but I have it in my working directory....


It works! Thank you very much!
Alex

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com