How do I change the block parameters in a Simulink model through matlab script?

15 views (last 30 days)
I'm working on a simple pendulum design and I was looking to make interaction with the simulink model easier by creating a matlab script where you can change the pendulum weight and length of the string by modifying the parameters in the matlab script. However I'm unsure on how to do this. I'm pretty new to matlab hence my lack of knowledge on something which seems rather simple and was wondering if anyone could point me in the right direction to start?

Accepted Answer

ES
ES on 31 Jul 2017
two ways: 1. Create workspace variables in the m script. Refer the variables in the constant blocks instead of direct values. Eg, in m script, create PENDULUM_LENGTH = 10. Use this "PENDULUM_LENGTH" in your model instead of 10.
2. Use set_param Using set_param command, you can modify the parameters of model. Example:
set_param(blockpath, 'value', '10');
In both cases, for model to know the updated value, you need to do an model update.
set_param(bdroot,'SimulationCommand','Update')
  1 Comment
Ellis Wilcox
Ellis Wilcox on 31 Jul 2017
I've tried this with my model but doesn't seem to function as required. The block I'm trying to modify from the script in a solids block from the simMechanics library. Is it possible to modify the parameters of a simMechanics block from a matlab script?

Sign in to comment.

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!