how to made a group of mixed type variables available in different routines without using global?

조회 수: 2 (최근 30일)
Hello,
How to made a group of mixed type of variables available in different routines without using global?
Say I have 10 variables (some string and some numbers [some integrers and some float]).
I need to have these variables accessible to various routines that are locatated (hierachely) at different levels.
The simple way would be to use Global, which I understand is not advisable (also tried and found out why it is indeed unadvisable)
Thank you
  댓글 수: 6
Adam Danz
Adam Danz 2022년 1월 2일
편집: Adam Danz 2022년 1월 2일
If you're comfortable with OOP, you could save values as properties of an object so that any function that has access to the object handle can access the properties. This approach is similar to storing values in a structure but also allows for the use of findobj() to get the handle of the object even if the handle is not passed to or within scope of the function.
But I would pass the values as a table or structure or use nested functions. If the values are stored in vectors and thier indicies correspond to each other, I'd strongly recommend using a table.

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

답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by