Filter löschen
Filter löschen

Getting app data into a script (old guidata)

16 Ansichten (letzte 30 Tage)
Jeffrey Topp
Jeffrey Topp am 9 Nov. 2023
Kommentiert: Jeffrey Topp am 10 Nov. 2023
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.

Antworten (1)

atharva
atharva am 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!
  1 Kommentar
Jeffrey Topp
Jeffrey Topp am 10 Nov. 2023
Thanks for the response. I was hoping not to run these scripts as functions as the scripts call other scripts and they populate the workspace. That's why I was going for sharing like guidata.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by