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개)
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
2021년 5월 24일
편집: thenuka perera
2021년 5월 24일
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
2021년 5월 24일
편집: thenuka perera
2021년 5월 25일
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
2021년 5월 25일
...any luck?
thenuka perera
2021년 5월 25일
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
2021년 5월 26일
카테고리
도움말 센터 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!