How do I fix a variable to a certain number??

Hi Im trying to fix a variable to a certain number.
I have set a variable called 'cx' as randi([10,30]) in GUI, but later on somehow it doesn't recognize cx and just leaves it as undefined. So when I define it again as randi([10,30]), obviously it gives another number, different from the initial one.. how do I fix this variable as a constant throughout the whole loop??

3 comentarios

Heejin Kim
Heejin Kim el 23 de Feb. de 2015
Oh by the way, from what I have written above, it might seem like the definition of cx is the problem, but what Im trying to do is just fix it as a constant. cuz cx=randi([10,30]) worked perfectly fine in other part of the loop
Rick Rosson
Rick Rosson el 23 de Feb. de 2015
Please post your code, or at least a sub-set that shows an example of the issue.
dpb
dpb el 23 de Feb. de 2015
"...it might seem like the definition of cx is the problem, but what I'm trying to do is just fix it as a constant."
Matlab does NOT have the concept of a constant variable (const in C, PARAMETER in Fortran). A variable is a variable; you can only keep it a constant once it's defined by ensuring by code logic that it is only ever defined that one time.

Iniciar sesión para comentar.

Respuestas (2)

Greig
Greig el 24 de Feb. de 2015
I suspect that cx is defined in a callback function somewhere, but is not passed back to the GUI handles, so that to the other GUI function, cx is undefined. Have a look at Share Data Among Callbacks or try
doc guidata
Or post part of your code and we can be more specific about how to fix it.
mohammed alwaely
mohammed alwaely el 27 de Nov. de 2019

0 votos

how to fix this P/Po as one variable equal to zero???

Categorías

Más información sobre Fortran with MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 23 de Feb. de 2015

Respondida:

el 27 de Nov. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by