Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
Md Nahid Hossain Khan
Md Nahid Hossain Khan am 8 Okt. 2019
Kommentiert: dpb am 8 Okt. 2019
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 Kommentar
dpb
dpb am 8 Okt. 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...

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by