Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How can I run a SimMechanics simulation from a matlab script file/ workspace?

Asked by Dave on 25 Oct 2012

I have a script file which currently uses "From Workspace" / "To workspace" blocks as inputs / outputs for a simMechanics model. This works fine. However I wish to loop through many simulations of the model in my script, so that I can take the output of the model on a first run, do something with that output in my script file and then update the input of the model and run it again, and so on.

How would I do this? Any help would be appreciated!

Dave

Products

No products are associated with this question.

1 Answer

Answer by pouya jamali on 27 Oct 2012
Accepted answer

I think you can use sim command to run your simulink block diagram from your script m-file ... sim('block diagram name') stay in touch just if your problem persists more ...

2 Comments

Dave on 27 Oct 2012

Thanks Pouya, you are absolutely right, I appreciate your input!

pouya jamali on 27 Nov 2012

An other way to do that is to use following commands:

set_param('modename','SimulationCommand','start') set_param('modename','SimulationCommand','pause') set_param('modename','SimulationCommand','continue') set_param('modename','SimulationCommand','stop')

and a Pause block on your model. the advantage of this method is to avoid compiling and initialization of the simulation in each iteration. It saves time.

pouya jamali

Contact us