Time dependent variable during simulation

36 views (last 30 days)
Viktor Frederic Felix Brandt
Commented: Mark McBroom on 26 Dec 2020
Dear Community,
i want create a time dependent variable (which represent my young modul and Stiffness of a beam in a Simscape model).
I want to change the stiffness during the simulation depending on the time.
I can not simply connect my stiffness variable to the Simscape block.
First i tried to do it with a signal builder, but was not albe to save the output into a variable.
Then i tried to run the simulation with a matlab script. But i was not able to define the variables during the simulation. So the problem is that first he run the simulation and then he modify the parameter.
my script:
clear all
close all hidden
if t<1
a,b are the stiffness variables of two seperate bodies.
I am no expert in matlab, so there is a possibility that i already made some mistakes... but without the stiffness parameters the model is fine.
Hope you can help me thank you!

Answers (1)

Mark McBroom
Mark McBroom on 25 Dec 2020
The sim() command doesn't return until the simulation is complete. An easy way to accomplish what you want to do is to use the Simulink Clock block and feed this into a conditional block and then switch block to switch between two different costant values. If you have more than 2 values to switch between, you could feed the clock block into a lookup table which would contain time-value pairs.
Mark McBroom
Mark McBroom on 26 Dec 2020
Hi Viktor,
I misunderstood your question... I thought your parameter was in a constant block. For the above dialog parameter "Youngs Modulus", I am not sure if it is possible to change the parameter value during the course of the simulation. To figure this out, do the following:
  1. Interactively run your simulation for a few seconds, then select the "Pause" button.
  2. Change the value of b in the workspace
  3. Resume the simulation.
Did your model have the expected change in behavoir with the changed value of b? If it did, then you might be able to use the pause/resume feature as described here to run your simulation for a specified time, then pause, change the value of b and then resume.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by