Running a Simulink Model from a function called by a GUI

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

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?
Yes, the simulation runs fine using a script.
Some of the elements of my simulation are variables defined in the script (or in the GUI by the user).
I've made some changes to run the simulation using a function.
There are 3 differents simulations, that were callled by three differents scripts. I've merged all of this in a single function and the user chooses through a button group which one he wants to simulate (I don't know if I messed something up here or if this could be the cause, but I don't think so).
Also, to call from inside a function I changed the options of the simulation (I didn't have to do this for the script):
options = simset('SrcWorkspace','current');
The Sample Time (Ts) is defined by the switching frequency of my model divided by the number of points per cycle.
This is how I call the simulation:
% Chama a simulação em Simulink - editar o nome da simulação
sim(simulacao,[Tinicial Tfinal], options);
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.
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?
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)

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!