필터 지우기
필터 지우기

How do I communicate between an AppDesigner app and a function

조회 수: 7 (최근 30일)
Roland Wessling
Roland Wessling 2017년 7월 13일
댓글: Cris LaPierre 2019년 2월 6일
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?!

답변 (1개)

Mukul Rao
Mukul Rao 2017년 7월 18일
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
Cris LaPierre
Cris LaPierre 2019년 2월 6일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by