Hi All,
I was following a training video on how to learn to make a GUI(Basic) on a second order dynamic system, using zeta as a variable. I want display the value of zeta everytime I ran the simulation. but I only get dataN values. I have attached the files created as part of the training video - I added the legend commands trying to make it work, but di not work!
Thanks for your help!
Gera

 Réponse acceptée

Walter Roberson
Walter Roberson le 16 Déc 2020
legend(sprintf('\\zeta = %g',zeta), 'interpreter', 'latex');
Notice the \\

Plus de réponses (1)

VBBV
VBBV le 13 Déc 2020
Modifié(e) : VBBV le 13 Déc 2020
%rue
legend(sprintf('\zeta = %d',zeta));
Use sprintf in legend in pushbutton callback function

6 commentaires

Gerardo Ortega
Gerardo Ortega le 15 Déc 2020
Thanks - Now the values get updated and it is display in the plot, however the color does not update to the most recent graph and the previuos values don't state in the grapg - it appears the like the hold on command is not working.
VBBV
VBBV le 15 Déc 2020
Modifié(e) : VBBV le 16 Déc 2020
%true
legend(sprintf('\zeta = %f',Zeta), sprintf('\zeta = %f',Zeta), sprintf('\zeta = %f', Zeta));
You are using zeta as variable to store damp value. It is built-in function in matlab.
Change it to and Try the above
VBBV
VBBV le 15 Déc 2020
Modifié(e) : VBBV le 15 Déc 2020
In your callback function you should change the variable zeta to something like Zeta or ZZeta etc
%true
Zeta = get(handles.slider1,Value)
VBBV
VBBV le 15 Déc 2020
However using a \ e.g. \zeta will not have problem. It will produce symbol instead
Walter Roberson
Walter Roberson le 16 Déc 2020
zeta is not a reserved word.
Avoiding using a variable name should be done if:
  • the name is easy to confuse with other names, such as l1 being easy to confuse with 11
  • the name is used so often for one purpose that seeing it will cause confusion, such as pi = sqrt(2)
  • the name is the same as a frequently used function so it is likely to confuse readers, such as length
  • the name is so commonly used as a function that you are likely to confuse yourself, such as sum
  • assigning to the name can make use difficult, such trying to remove a variable named "clear"
In most circumstances zeta does not fall under any of those. There is a zeta function but the use is so uncommon that people are more likely to think of zeta as a variable instead of a function.
Walter Roberson
Walter Roberson le 16 Déc 2020
Using \zeta inside sprintf because \ introduces escape sequences in that context. \n \t and so on. \z is not a valid escape and will lead to errors. You need \\zeta

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by