How do I run a model in Simulink from my MATLAB function where my Simulink parameters are defined in this function?

R
Rebeccashah · Jul 31, 2020 · 3K views
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
Profile picture of Prashant Kumar
Prashant Kumar PhD Expert
Answered Sep 8, 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.

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!