This is definitely possible! You can use the callback-function StartFcn in the model properties (or in the block itself). This function is being executed each time the model is being simulated. Then add a check for the solver-type that throws an error if it is set to Fixed-step.
Here is the code to add:
if(strcmp('Fixed-step',get_param(bdroot,'SolverType')))
error('Do not use a fixed-step solver because the results are not correct!');
end
This throws the following error in the Diagnostic Viewer when your model's name is test:
Detailed explanation of the code
We get the name of the top-level Simulink system by executing bdroot . This system name is then used for the call to get the solver-type with get_param(bdroot,'SolverType'). Then we use strcmp to compare the returned string with 'Fixed-step'. If the current solver is fixed-step then strcmp returns 1, so we enter the if-statement and throw the error with the error-function.
Add it to a block
To add the callback-function to a block, right-click the block, then on Properties as shown in the screenshot below:
And then go to Callbacks -> StartFcn and paste the code:
Add it to a model
To add the callback-function to the model click on Model Properties as shown in the screenshot below:
And then go to Callbacks -> StartFcn and paste the code:
Short version
This is definitely possible! You can use the callback-function
StartFcn
in the model properties (or in the block itself). This function is being executed each time the model is being simulated. Then add a check for the solver-type that throws an error if it is set toFixed-step
.Here is the code to add:
This throws the following error in the Diagnostic Viewer when your model's name is
test
:Detailed explanation of the code
We get the name of the top-level Simulink system by executing
bdroot
. This system name is then used for the call to get the solver-type withget_param(bdroot,'SolverType')
. Then we usestrcmp
to compare the returned string with'Fixed-step'
. If the current solver is fixed-step thenstrcmp
returns1
, so we enter the if-statement and throw the error with theerror
-function.Add it to a block
To add the callback-function to a block, right-click the block, then on Properties as shown in the screenshot below:
And then go to Callbacks -> StartFcn and paste the code:
Add it to a model
To add the callback-function to the model click on Model Properties as shown in the screenshot below:
And then go to Callbacks -> StartFcn and paste the code:
That's it. I hope it helps...