Declare multiple global variables at once
4 ビュー (過去 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?
1 件のコメント
回答 (3 件)
Samuel Vergara
2016 年 7 月 2 日
Use a structure. K.a=1; K.b=2; K.etc=3; Then you pass K.
Regards
0 件のコメント
Image Analyst
2016 年 7 月 2 日
Several alternative methods are listed in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!