Declare multiple global variables at once

11 visualizaciones (últimos 30 días)
Allie Gehris
Allie Gehris el 2 de Jul. de 2016
Respondida: Image Analyst el 2 de Jul. de 2016
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 comentario
Star Strider
Star Strider el 2 de Jul. de 2016
Please do not use global variables. Pass them as parameters instead.

Iniciar sesión para comentar.

Respuestas (3)

Samuel Vergara
Samuel Vergara el 2 de Jul. de 2016
Use a structure. K.a=1; K.b=2; K.etc=3; Then you pass K.
Regards

Walter Roberson
Walter Roberson el 2 de Jul. de 2016

Image Analyst
Image Analyst el 2 de Jul. de 2016

Categorías

Más información sobre Numeric Types en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by