Update the Legend dataN value in GUI

1 view (last 30 days)
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

Walter Roberson
Walter Roberson on 16 Dec 2020
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
Walter Roberson
Walter Roberson on 16 Dec 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 on 16 Dec 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

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!