Declare multiple global variables at once

7 次查看(过去 30 天)
I'm writing a fairly meaty code with lots of sub functions and scripts. To avoid human error, I made a script that contains hundreds of constants and unit conversions. The code would look something like this:
function myCode
run UnitConverter;
[a,b] = mySubFunction(c,d,e)
end
Where mySubFunction would call the variables assigned in UnitConverter. However, I really don't want to declare every single individual variable as a global one such that mySubFunction can read it. Is there a better way to do this?

回答(3 个)

Samuel Vergara
Samuel Vergara 2016-7-2
Use a structure. K.a=1; K.b=2; K.etc=3; Then you pass K.
Regards

Walter Roberson
Walter Roberson 2016-7-2

Image Analyst
Image Analyst 2016-7-2

类别

Help CenterFile Exchange 中查找有关 Scope Variables and Generate Names 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by