MATLAB Answers

Running a Simulink Model from a function called by a GUI

4 views (last 30 days)
Pedro Augusto de Castro e Castro
Commented: Fangjun Jiang on 20 Jan 2020
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

Show 2 older comments
Fangjun Jiang
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
Hey man,
So how do I do this?
I just copied the content of the function and put the values manually and the simulation runs fine.
I really don't understand what the problem is.
Also, the user defines a interval of frequencies, and the simulation runs several times, each time with a different sample time. The first time the simulation is ran everything is fine, but on the second time this problem arises.
Any ideas?
Fangjun Jiang
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.

Sign in to comment.

Answers (0)

Sign in to answer this question.


Translated by