Running a Simulink Model from a function called by a GUI
Show older comments
Hello everyone,
I want to call a Simulink Model from inside a function that is called by a button press in a GUI. However, I've got a problem that does not occur when I run this model from a script. (simulaInv is the function, simulaInv_v2 is the GUI and the model is inversor_2n).
Error using simulaInv (line 131)
Error due to multiple causes.
Error in simulaInv_v2>simular_Callback (line 362)
simulaInv(hObject, handles);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in simulaInv_v2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)simulaInv_v2('simular_Callback',hObject,eventdata,guidata(hObject))
Caused by:
Error using simulaInv (line 131)
Invalid setting for fixed-step size (8.1380208333333339E-7) in model 'inversor_2n'. All sample times in your model must be an integer multiple of the fixed-step size.
Error using simulaInv (line 131)
The sample time period (1.403107040229885E-7) of 'inversor_2n/powergui/EquivalentModel1/State-Space' is not an integer multiple of the fixed step size (8.1380208333333339E-7) specified for model.
Error while evaluating UIControl Callback.
I don't understand because if I run the same model using a script it runs just fine, without any errors.
5 Comments
Fangjun Jiang
on 16 Jan 2020
The error is about the fixed step size and sample time of the model. Are you sure your model runs normally using a script? You could have model open. Make sure it runs normally through the script or manually. And then try to run it through the GUI call.
Does your GUI call change any of the model parameters?
Pedro Augusto de Castro e Castro
on 16 Jan 2020
Fangjun Jiang
on 16 Jan 2020
If you still have errors, then add line before running the simulation to check the value of step size and sample time, using get_param(). I am sure the error was caused by the different values.
Pedro Augusto de Castro e Castro
on 17 Jan 2020
Edited: Pedro Augusto de Castro e Castro
on 20 Jan 2020
Fangjun Jiang
on 20 Jan 2020
It seems there is nothing wrong calling to run the simulation from GUI. The problem is the model with the parameters. The error message is clear. You can't have a fixed step size as 8.1E-7 while there is a sample time of 1.4E-7 in the model.
All sample times in your model must be an integer multiple of the fixed-step size.
If you sample time is 1.4E-7, then the fixed step size has to be at least 1.4E-7, or better much smaller, but must be an integer fraction of the sample time, such as 7E-8, 3.5E-8, etc.
Answers (0)
Categories
Find more on Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!