Azzera filtri
Azzera filtri

How to make a "local global " variable?

2 visualizzazioni (ultimi 30 giorni)
wei zhang
wei zhang il 31 Mag 2019
Commentato: wei zhang il 1 Giu 2019
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 Commenti
Rik
Rik il 31 Mag 2019
@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 il 1 Giu 2019
@Stephen @Rik
Yes. You are right. Thank you for your good solution.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 31 Mag 2019
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

Più risposte (0)

Categorie

Scopri di più su Debugging and Analysis in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by