I have different callbacks in an Matlab App Designer App. In my case several buttons. I need to use the same variables for that.
I only get an error when using a variable I created in one Callback in another...
To clear one or more specific variables from the current workspace, use clear name1 ... nameN . To clear all variables from the current workspace, use clear or clearvars . To clear all global variables, use clear global or clearvars –global .
A callback is a function that executes when a user interacts with a UI component in your app. You can use callbacks to program the behavior of your app.
To create a new variable, enter the variable name in the Command Window, followed by an equal sign ( = ) and the value you want to assign to the variable. For example, if you run these statements, MATLAB adds the three variables x , A , and I to the workspace: x = 5.71; A = [1 2 3; 4 5 6; 7 8 9]; I = besseli(x,A);
Since MATLAB automatically passes the component executing the callback to the callback function as src, you can access the figure from within the callback by using the ancestor function. Then, you can use the figure to access the panel and the text.
All callbacks in App Designer have the following input arguments in the function signature: app — The app object. Use this object to access UI components in the app as well as other variables stored as properties. event — An object that contains specific information about the user's interaction with the UI component.
In simple applications, instead of storing your app data in the UserData property, you can store data as variables in your main app function, and then provide each callback with the relevant data using input arguments or nested functions. To access app data in a component callback function, use one of these methods:
In apps with multiple interdependent UI components, the callback functions often must access data defined inside the main app function, or share data with other callbacks. For instance, if you create an app with a list box, you might want your app to update an image based on the list box option the app user chooses.
I think I got your problem.
The easiest way is in beginning to create a new property (red button on the top left in EDITOR) and use it as a variable throughout the code.
Be careful to use app.variablename
to address the variable.
If your code is already finished and you just discovered that error, you can set properties for only the variables you need to exchange and then get them like this:
set property:
properties (Access = private)
varone %first variable
vartwo % second variable
...
end
get Data for Exchange:
varone = app.varone; %(now you can use varone instead of app.varone)
make it public again at the end of your callback:
app.varone = varone;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With