Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
Md Nahid Hossain Khan
Md Nahid Hossain Khan el 8 de Oct. de 2019
Comentada: dpb el 8 de Oct. de 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 comentario
dpb
dpb el 8 de Oct. de 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...

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by