How to make a "local global " variable?

조회 수: 4 (최근 30일)
wei zhang
wei zhang 2019년 5월 31일
댓글: wei zhang 2019년 6월 1일
Hello,
I would like to share some variables among some functions. It is inconvenience to make them all as arguments, because that makes the command too long. Is there a way to add these variable in a special "global variable pool"? A global variable is defined under all functions, which is not appropriate for me. I only want them to be shared among several functions.
Thank you for any helpful suggestion.
  댓글 수: 3
Rik
Rik 2019년 5월 31일
@Stephen since using a struct is likely to be the best solution by far, I would suggest you move it to the answers section.
wei zhang
wei zhang 2019년 6월 1일
@Stephen @Rik
Yes. You are right. Thank you for your good solution.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2019년 5월 31일
No, that does not exist.
  • you can create accessor functions that deal with persistent variables inside a private directory
  • you can put the functions togther in a class with class variables
  • if all relevant functions can be in the same source file, then you can use nested functions with shared variable
  • or pass a struct instead

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by