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

 채택된 답변

Walter Roberson
Walter Roberson 2020년 12월 16일

1 개 추천

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

추가 답변 (1개)

VBBV
VBBV 2020년 12월 13일
편집: VBBV 2020년 12월 13일

1 개 추천

%rue
legend(sprintf('\zeta = %d',zeta));
Use sprintf in legend in pushbutton callback function

댓글 수: 6

Gerardo Ortega
Gerardo Ortega 2020년 12월 15일
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 2020년 12월 15일
편집: VBBV 2020년 12월 16일
%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 2020년 12월 15일
편집: VBBV 2020년 12월 15일
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 2020년 12월 15일
However using a \ e.g. \zeta will not have problem. It will produce symbol instead
Walter Roberson
Walter Roberson 2020년 12월 16일
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 2020년 12월 16일
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

댓글을 달려면 로그인하십시오.

카테고리

제품

질문:

2020년 12월 13일

댓글:

2020년 12월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by