Update the Legend dataN value in GUI

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

 Accepted Answer

legend(sprintf('\\zeta = %g',zeta), 'interpreter', 'latex');
Notice the \\

More Answers (1)

VBBV
VBBV on 13 Dec 2020
Edited: VBBV on 13 Dec 2020
%rue
legend(sprintf('\zeta = %d',zeta));
Use sprintf in legend in pushbutton callback function

6 Comments

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.
%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
In your callback function you should change the variable zeta to something like Zeta or ZZeta etc
%true
Zeta = get(handles.slider1,Value)
However using a \ e.g. \zeta will not have problem. It will produce symbol instead
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.
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

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!