Declare multiple global variables at once

8 ビュー (過去 30 日間)
Allie Gehris
Allie Gehris 2016 年 7 月 2 日
回答済み: Image Analyst 2016 年 7 月 2 日
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 件のコメント
Star Strider
Star Strider 2016 年 7 月 2 日
Please do not use global variables. Pass them as parameters instead.

サインインしてコメントする。

回答 (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 Center および File ExchangeScope 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