필터 지우기
필터 지우기

Declare multiple global variables at once

조회 수: 13 (최근 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 CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by