Time dependent variable during simulation

57 views (last 30 days)
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:
clc
clear all
close all hidden
a=1
b=1
sim('simscapemodel_stiffness')
t=ans.time.Time
if t<1
a=500
b=20
else
a=20
b=500
end
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!
Viktor

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.
  2 Comments
Viktor Frederic Felix Brandt
Hi Mark,
Thank you for your Answer, i tried to do it in your way. It works but how do i tell Simulink that the youngs-modul ist one of the two constants?
I can only give him a variable like a or b and can not make a linkage between a constant and the block. When i build it and run it, i can switch the constants but the youngs modul stays the same... because he does not know that the constants represent a or b (the variables)...
Hope you also know how to solve this...
merry Christmas and greetings
Viktor
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.

Categories

Find more on 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!