Borrar filtros
Borrar filtros

How do I communicate between an AppDesigner app and a function

7 visualizaciones (últimos 30 días)
Roland Wessling
Roland Wessling el 13 de Jul. de 2017
Comentada: Cris LaPierre el 6 de Feb. de 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?!

Respuestas (1)

Mukul Rao
Mukul Rao el 18 de Jul. de 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 comentario
Cris LaPierre
Cris LaPierre el 6 de Feb. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer 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