Clear Filters
Clear Filters

How can I set a block of code from one m file into another m file?

3 views (last 30 days)
I need to run a code to simulate result. I have several inputs as m file and I need to put a block of code into another input m file. How can I do that?
suppose, case1.m, case2.m. bob.m, and paul.m are m files and these are the input for simulation.
I have to write the structural array into a seperate m file during running the simulation and put it into case2 anyhow even though the case2.m doesn't contain this structural array normally. How can I do that?
a=case1;
b=case2;
c=bob;
d=paul;
run=showresult(a,b,c,d);
plot(run);
header = {'Name' 'Type' 'Address' 'Phone No'};
case2.ext=cell2table({
1.0000 2.0000 0.1000 0.1000
2.0000 2.0000 0.1000 0.1000
3.0000 2.0000 0.1000 0.1000
4.0000 2.0000 0.1000 0.1000
}, 'VariableNames',header);
  1 Comment
dpb
dpb on 8 Oct 2019
Write as functions and pass the struct as an argument instead...or, you could use nested functions perhaps and then the included function could have access to the variables contained in the higher scope of the containing m-file/function.
See documentation for function and the supporting discussion on program structure for details, examples...

Sign in to comment.

Answers (0)

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!