Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
Md Nahid Hossain Khan
Md Nahid Hossain Khan le 8 Oct 2019
Commenté : dpb le 8 Oct 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 commentaire
dpb
dpb le 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...

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Workspace Variables and MAT-Files dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by