Using the matlab app designer, I want to somehow run a function that can modify data within the app without specifically calling it.
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Justus Quint Von Lengerke
el 14 de Jul. de 2023
Respondida: Walter Roberson
el 18 de Jul. de 2023
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 comentarios
Mario Malic
el 17 de Jul. de 2023
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');
Respuestas (1)
Walter Roberson
el 18 de Jul. de 2023
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.
0 comentarios
Ver también
Categorías
Más información sobre Data Type Identification 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!