how to share multiple variables in different m files?
Show older comments
Now i have two solutions to address the problem.
- The one is set all the variables need to share to ouptput variable,and input them when it's used in other function.
- The other is set all these variables to global variable.Does Matlab can address it by other better solution?
Accepted Answer
More Answers (1)
Jasper
on 29 Aug 2014
What type of program are you using this in? Are you using some form of parallel processing?
If not, I would recommend passing variables as a structure to the functions, and returning a similar (updated) structure as the output of the functions.
For instance:
function output=fcn(input)
output=input;
output.var1=input.var1*20;
end
p.var1=2^8;
p.var2='somestring';
p=fcn1(p);
Categories
Find more on Whos in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!