Getting app data into a script (old guidata)
7 views (last 30 days)
Show older comments
I've created a GUI in App Designer which has a button that calls another script. How do I access the values of the app components from inside my script? In the guide days I would use guidata(gcf). I would rather not pass all the app component values into the script as function parameters, that would be tedious.
0 Comments
Answers (1)
atharva
on 9 Nov 2023
Hey Jeffrey,
I understand that you are trying to access the values of your app components from another script.
In App Designer, you can access the values of app components from within another script by using the app object. The app object represents the instance of your app, and you can use it to get or set the values of app components.
Here's an example:
1. In your App Designer, let's say you have a button with the Tag "myButton". In the button's callback function, you can call your external script and pass the app object to it.
methods (Access = private)
% Button pushed function: MyButton
function MyButtonPushed(app, event)
% Call your external script and pass the app object
externalScript(app);
end
end
2. In your external script, you can receive the app object and access the values of the components.
function externalScript(app)
% Accessing the value of a component (assuming you have a component with Tag 'myComponent')
componentValue = app.myComponent.Value;
end
By passing the app object to your external script, you have access to all the components and their values. You don't need to pass each value as a separate parameter.
This approach is more in line with the object-oriented nature of App Designer compared to the guidata method.
I hope this helps!
See Also
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!