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
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