Real-Time Interface between App in AppDesigner and Simulink using parsim

9 Ansichten (letzte 30 Tage)
I would like to optimize my progress bar in my Matlab app, which I am building in AppDesigner. I am currently using the app to start my Simulink model with parsim and simulate several simulation runs. However, I do not get any feedback on the progress of the individual simulations. I got the Listener option as a tip. I have implemented this. The specially created updategui.m file works. My question is, how can I combine parsim and the call of the updategui.m file? As soon as the parsim command is executed, I can no longer execute anything else. However, according to the instructions, I have to execute the updategui.m file as soon as the simulation is running. Otherwise exec_event_listener does not work.
Thank you.

Akzeptierte Antwort

prabhat kumar sharma
prabhat kumar sharma am 23 Jan. 2025
Hello Fabian,
To enhance your progress bar in a MATLAB App Designer application while using parsim for running parallel simulations, you can utilize listeners to track the simulation progress. The main idea is to attach a listener to the SimulationOutput object generated by parsim, and use this to refresh your GUI's progress bar.Steps to Implement a Progress Bar with parsim:
  1. Prepare Your Simulink Model:First, make sure your Simulink model is set up to provide progress updates. This could involve adding a custom block or using a MATLAB Function block to send updates to the MATLAB workspace or trigger an event listener.
  2. Create a Listener for parsim:When you execute parsim, the SimulationOutput object it returns can have listeners attached to it. These listeners will be responsible for updating your progress bar.
  3. Refresh the GUI:The listener should execute a function (such as updategui.m) to update your progress bar in the app.
% Inside your App Designer app, set up the parsim and listener
function runSimulations(app)
% Configure your Simulink model for parallel simulation
in = Simulink.SimulationInput('your_model_name');
% Adjust the input if necessary (e.g., set parameters)
% Set up the listener for progress updates
listener = @(src, event) updateProgress(app, event);
% Run parsim with the listener
parsimOptions = 'ShowProgress', 'on', 'TransferBaseWorkspaceVariables', 'on';
simOut = parsim(in, ...
'ShowProgress', 'on', ...
'TransferBaseWorkspaceVariables', 'on', ...
'SetupFcn', @(x) addlistener(x, 'SimulationOutput', 'PostSimFcn', listener));
end
% Function to update progress in the GUI
function updateProgress(app, event)
% Extract progress information from event
progress = event.Progress;
% Update your progress bar in the app
app.ProgressBar.Value = progress; % Assuming you have a ProgressBar component
end
  1 Kommentar
Fabian
Fabian am 23 Jan. 2025
Thank you for your answer. But now i got an error executing SetupFcn.
Error using nhf>@(x)addlistener(x,'SimulationOutput','PostSimFcn',listener) (line 233)
Not enough input arguments.
in my simulink-modell i do the following. Is something wrong here?
Should i write listener = @nhf (Class)?
This function run in nhf (Class)
function Simulate(obj)
for simNr = numel(obj.Data):-1:1
in(simNr) = Simulink.SimulationInput(obj.simModel);
for prop = fieldnames(obj.Data(simNr))'
in(simNr) = in(simNr).setVariable(char(prop), obj.Data(simNr).(char(prop)));
% tbd: assign to baseworkspace
% assignin('base',char(prop), obj.Data(simNr).(char(prop)));
end
if isdeployed
in(simNr) = simulink.compiler.configureForDeployment(in(simNr));
end
end
% - Disable the automatic opening of the visualization viewer
% - Should be done for all models before compiling
% -------------------------------------------------------------
%open_system(obj.simModel);
%set_param(obj.simModel, 'SimMechanicsOpenEditorOnUpdate', 'off');
% Set up the listener for progress updates
listener = @(src,event) updateProgress(app,event);
% Save results internally
obj.simOut = parsim(in, ...
'ShowProgress','on',...
'TransferBaseWorkspaceVariables','on',...
'SetupFcn',@(x) addlistener(x, 'SimulationOutput', 'PostSimFcn', listener));

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Configure and View Diagnostics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by