KKS
KKS

Reputation: 1389

Matlab : running m-files by running another m-file

I would like to execute multi m-files by executing another m-file.

For example,

When I have two m-files like below,

a.m file in folder A,

% a.m file
val1=1;
save('val1.mat','val1')

And then, b.m file in folder B,

% b.m file
val2=2;
save('val2.mat','val2')

I would like to running the a.m file and b.m file by running c.m file, which is in folder C.

Possible code of c.m file would like below,

runMFIle('a.m', directory A);
runMFIle('b.m', directory B);

And then, val1.mat would be saved in folder A, while val2.mat would be saved in folder B.

Is it possible in matlab?

Upvotes: 0

Views: 177

Answers (1)

Zoltan Csati
Zoltan Csati

Reputation: 699

Yes, it is. You just have to add directory A and directory B to the search path where MATLAB can find them. So inside your c.m, write

addpath('../DirA');
addpath('../DirB');

Upvotes: 1

Related Questions