I want to simulate a model using the SIM command from inside a MATLAB function. My model has mask parameters that are variables defined in my function, fcn_name.m. I know that Simulink uses the variables stored in the base workspace. Is there a way to simulate my model from inside my function without creating variables in the base workspace?
Prashant Kumar answered .
2025-11-20
When using variable mask parameters in Simulink, the base workspace is the default source workspace of Simulink. However, by using the SIMSET command, this workspace can be changed. SIM is then used with this options structure created by SIMSET. The following is an example on how to do this.
options = simset('SrcWorkspace','current');
sim('modelname',[],options)
This will change the source workspace of Simulink to the current workspace which is your function's workspace. Consult the currrent product documentation for more information about SIMSET.