Define common variable in matlab app/GUI

i have design matlab application. in there i take three input values(x,y,z) from user and after calculation ploting a graph. there are three push buttons becuse user allow to plot 3 graphs with 3 different values . i have code one push button and after run it and click graph being plot. and when i click the 2 nd push button also graph being plot and 3 rd button also do the same.
in the code i used properties for x.y,z and code one push button in there i include if condition becuse if user enter 0, and then add the equation then plot and save property(app.time =x) then in second and third push button call it(x = app.time) add the equation and plot
but there are 2 problems in application.
  • 2 nd push button is not working if i didnt use 1 st push button
  • and when i plot graphs by clicking one push button after another button and plot 3 graphs(input values[x,y,z] for the eah gaphs are different) graphs shapes same
where is im mistaken?

답변 (1개)

Adam Danz
Adam Danz 2021년 5월 24일
편집: Adam Danz 2021년 5월 24일

1 개 추천

The values should be stored as app properties so that they are available from anywere within the app.
Make sure you assign a default value for each property so your app behaves as expected if the user does not define all 3 values.

댓글 수: 8

thenuka perera
thenuka perera 2021년 5월 24일
편집: thenuka perera 2021년 5월 24일
Thank you. but i have stored in properties.
and then set the values in push button 01. then call the values in push button 3 and 2
Adam Danz
Adam Danz 2021년 5월 24일
I don't know what this image refers to. I don't see where you're defining the properties and setting thier values. Also, I'd need to see any error messages you're getting.
What does it mean, "2nd push button is not working if i didnt use 1st push button" ? I don't understand what "not working" means.
I don't know what x|y|z are or where they come from.
thenuka perera
thenuka perera 2021년 5월 24일
편집: thenuka perera 2021년 5월 25일
let me send the full code, im not getting any errors. but my plotted graphs are same even the values are changed. it should be different when values changed.
Adam Danz
Adam Danz 2021년 5월 24일
> 2nd push button is not working if i didnt use 1st push button
The reason for this is explained in the last line of my answer. You aren't assigning default values to the time,omegan,omega,freq properties so they are undefined before you press the 1st button.
You can assign default values to them using,
properties (Access = private)
time = 1:10; % description
omegan = 0; % description
% etc...
end
> and when i plot graphs by clicking one push button after another button and plot 3 graphs(input values[x,y,z] for the eah gaphs are different) graphs shapes same
Based on what I see the three lines should look exactly the same. The only part of the code I see that updates the inputs is in X0VstButtonPushed. The X0 functions in all three callback function are the same and will produce the same results if provided with the same inputs. The only thing that differs is the color of line.
Adam Danz
Adam Danz 2021년 5월 25일
...any luck?
thenuka perera
thenuka perera 2021년 5월 25일
Thanks for the help. You might not understand my question. so what i did was copy and paste same code each button without using property option. Then user can plot three graphs even when the user enter 3 different inputs for 3 times. I was loking for way to reduce the codings. As in without using same code for each button.
Adam Danz
Adam Danz 2021년 5월 25일
> what i did was copy and paste same code each button without using property option
I saw that you were using the app properties option in the code you shared and since removed. Are you saying that you are using code that is different from the code you shared?
> I was loking for way to reduce the codings.
That's a very different question with a simple solution. If the values for the plots are produced internally you'll need one callback function to update the internally stored values and you only need one other callback function to manage the plotting for 3 different axes. The callback function will identify which button was pressed and will assign the plot to the corresponding axes.
thenuka perera
thenuka perera 2021년 5월 26일
oh! thanks ill try that

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

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

질문:

2021년 5월 24일

댓글:

2021년 5월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by