Question
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?
Expert Answer
Prashant Kumar
PhD Expert
Answered Aug 22, 2026
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.
Have a different question? Ask here
Related simulink Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →