Using the matlab app designer, I want to somehow run a function that can modify data within the app without specifically calling it.

조회 수: 12 (최근 30일)
I have a complicated program that includes hundreds of sub functions -- all of which are managed through a GUI made using the Matlab APP designer. One of the things I want to do is to call a standard function in my directory ("status.m"), and using this status function, edit properties within the app. However, even if app is in the working space, to edit any properties in the app, I need to call the app ("app.propertyIWantToEdit"). The only solution I know of so far would be to call the app as an input function through every function I have, which would be very inefficient and tedious.
Is there a way I could make a function that, in a sub function, independently calls up the app so it can modify data/change variables, so I don't need to manually call the app in the outer function?
  댓글 수: 9
Mario Malic
Mario Malic 2023년 7월 17일
You can use findall to find handle of the app and do whatever you need. However, you might need to specify something aditionally that you can identify your app with such as Name or Tag.
This will return handle of all opened figures, and will try to get the RunningAppInstance property.
% Get app handle
app = get(findall(groot, 'type', 'figure'), 'RunningAppInstance');
Justus Quint Von Lengerke
Justus Quint Von Lengerke 2023년 7월 18일
Thank you all for the responses. A few things got in the way meaning I'll be away from this project for a bit but I'll give these all a try and I'll let you know which method I went with. Thanks again!

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

답변 (1개)

Walter Roberson
Walter Roberson 2023년 7월 18일
function status(varargin)
persistent app
switch nargin
case 1
assert(~isempty(app), 'status must be called with app before it can be called without app');
statusValue = varargin{1};
case 2
app = varargin{1};
statusValue = varargin{2};
otherwise
error('status() must be called with 1 or 2 parameters');
end
switch statusVal
case 1
statusString = "Case 1";
case 4
statusString = "A not equal to B";
end
app.StatusLabelBox.Text = statusString;
end
status() must be called with app provided at least once before it is called without app provided. If called with a single parameter and this is not the first call then it uses the remembered app.
This code relies upon app being a handle class.

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by