Borrar filtros
Borrar filtros

Getting app data into a script (old guidata)

8 visualizaciones (últimos 30 días)
Jeffrey Topp
Jeffrey Topp el 9 de Nov. de 2023
Comentada: Jeffrey Topp el 10 de Nov. de 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.

Respuestas (1)

atharva
atharva el 9 de Nov. de 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 comentario
Jeffrey Topp
Jeffrey Topp el 10 de Nov. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by