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:
running scripts with a variable

Subject: running scripts with a variable

From: Mayowa Kassim Aregbesola

Date: 15 Jan, 2009 17:05:04

Message: 1 of 4

Hi guys,
I am trying to implement a code in matlab. I need to run a file based on the input i feed in

for instance I want to run testfile2.m

testcase = 2;
testfile = ['testfile', num2str(testcase), '.m'];

run testfile; %wish to run testfile2.m


how can I implement this.

thanks in advance

Subject: running scripts with a variable

From: David

Date: 15 Jan, 2009 17:14:02

Message: 2 of 4

"Mayowa Kassim Aregbesola" <mailmayowa@gmail.com> wrote in message <gknqc0$mu6$1@fred.mathworks.com>...
> Hi guys,
> I am trying to implement a code in matlab. I need to run a file based on the input i feed in
>
> for instance I want to run testfile2.m
>
> testcase = 2;
> testfile = ['testfile', num2str(testcase), '.m'];
>
> run testfile; %wish to run testfile2.m
>
>
> how can I implement this.
>
> thanks in advance

eval(testfile)

Subject: running scripts with a variable

From: Joerg Buchholz

Date: 15 Jan, 2009 17:21:01

Message: 3 of 4

"Mayowa Kassim Aregbesola" <mailmayowa@gmail.com> wrote in message <gknqc0$mu6$1@fred.mathworks.com>...
> Hi guys,
> I am trying to implement a code in matlab. I need to run a file based on the input i feed in
>
> for instance I want to run testfile2.m
>
> testcase = 2;
> testfile = ['testfile', num2str(testcase), '.m'];
>
> run testfile; %wish to run testfile2.m
>
>
> how can I implement this.
>
> thanks in advance

run(testfile)

Subject: running scripts with a variable

From: mayowa

Date: 15 Jan, 2009 18:22:02

Message: 4 of 4

Thanks both of them work without the '.m'

testfile = ['testfile', num2str(testcase)];

run(testfile);

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