Effacer les filtres
Effacer les filtres

How do I communicate between an AppDesigner app and a function

7 vues (au cours des 30 derniers jours)
Roland Wessling
Roland Wessling le 13 Juil 2017
Commenté : Cris LaPierre le 6 Fév 2019
I have been using the AppDesigner to create my UI. Since I find writing the actual functions much less convenient in AppDesigner than in the 'normal' MatLab class Editor, I would like to place all the functions I can in there. However, I cannot figure out how I can set values from AppDesigner controls from my Editor functions. For example, I want to create three colour histograms in the app and would like to send the data for that from the function placed in the 'normal' MatLab Editor. How do I do that? I locked up setappdata/getappdata but that does not seem to work?!

Réponses (1)

Mukul Rao
Mukul Rao le 18 Juil 2017
Hi,
Here is a simplistic template to illustrate the workflow to access App Designer plot data:
  • Create an axes for your application by dragging an "axes" component from the component library
  • In the App Designer "Code View", you will notice that a new "UIAxes" property is created and it has public access.
  • Right click on the app in Design View - Callbacks -> add startupFcn
  • Within the body of the "startupFcn" function, in code view, place the following line of code
histogram(app.UiAxes,randi([1 10],100)) %Plots a histogram of random integers on app startup
  • Save the application as "myapp.mlapp".
  • Instantiate the application either in a script or command line :
app = myapp
  • You can pass the "app" handle to any function created with the MATLAB editor as an input argument and basically modify the data property of the histogram to update its value
function myFunction(app)
%Do some work
app.UIAxes.Children.Data = newData;
% Note: Children might contain more than just a histogram if you have other plots inside the axes
end
  1 commentaire
Cris LaPierre
Cris LaPierre le 6 Fév 2019
This documentation page will walk you through how to do this. There is also an example at the bottom of the page you can open and inspect.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by