Define common variable in matlab app/GUI
Show older comments
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?
Answers (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 Comments
thenuka perera
on 24 May 2021
Edited: thenuka perera
on 24 May 2021
Adam Danz
on 24 May 2021
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
on 24 May 2021
Edited: thenuka perera
on 25 May 2021
Adam Danz
on 24 May 2021
> 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
on 25 May 2021
...any luck?
thenuka perera
on 25 May 2021
Adam Danz
on 25 May 2021
> 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
on 26 May 2021
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!