Discussion:
changing parameter in simulink during simulation.
(too old to reply)
ma
2006-05-19 18:42:10 UTC
Permalink
Hello,

I want to change the parameter of a block during simulation based on the
value of a signal. Is it possible? If yes how?



For example, assume that I have a sin block and I want that its frequency is
determines by the value of a signal. ( for example when the value of this
signal is 2, sin generate a 2K sin) How can design such model?



Best regards
Praetorian
2006-05-19 21:50:01 UTC
Permalink
Post by ma
Hello,
I want to change the parameter of a block during simulation based on the
value of a signal. Is it possible? If yes how?
For example, assume that I have a sin block and I want that its frequency is
determines by the value of a signal. ( for example when the value of this
signal is 2, sin generate a 2K sin) How can design such model?
Best regards
Hi, I don't have time to try this out but I have a couple of
suggestions. You should first turn off the 'Inline parameters'
optimization in the model's Configuration Parameters.

What you can do is create a variable in the workspace; let's say
'sineFreq' and type that into the frequency field of the sine block.
Now, compute the desired frequency value using the other signal and use
a To Workspace block to change the value of sineFreq in the workspace.
You must always ensure that that variable exists in the workspace
before running the model. You can use assignin and the model's InitFcn
callback to do this.

HTH,
Ashish.
Praetorian
2006-05-19 22:09:43 UTC
Permalink
Post by Praetorian
Post by ma
Hello,
I want to change the parameter of a block during simulation based on the
value of a signal. Is it possible? If yes how?
For example, assume that I have a sin block and I want that its frequency is
determines by the value of a signal. ( for example when the value of this
signal is 2, sin generate a 2K sin) How can design such model?
Best regards
Hi, I don't have time to try this out but I have a couple of
suggestions. You should first turn off the 'Inline parameters'
optimization in the model's Configuration Parameters.
What you can do is create a variable in the workspace; let's say
'sineFreq' and type that into the frequency field of the sine block.
Now, compute the desired frequency value using the other signal and use
a To Workspace block to change the value of sineFreq in the workspace.
You must always ensure that that variable exists in the workspace
before running the model. You can use assignin and the model's InitFcn
callback to do this.
HTH,
Ashish.
Ok, I did try it out and it doesn't work. What I figured out was that
once you change the workspace variable you need to do an update diagram
for Simulink to read the new value. So another solution I can think of
is to run your simulation using a script, search documentation for
'SimulationCommand'; you could start the simulation and step through
it, check sineFreq after every step and if the value has changed then
do an update diagram. This might be really slow; hopefully someone else
will have a better solution.

Also, if you only want to do this for the sine block then you can just
use the Use External Signal option to change the frequency as desired.
ma
2006-05-20 07:25:24 UTC
Permalink
Post by Praetorian
Post by Praetorian
Post by ma
Hello,
I want to change the parameter of a block during simulation based on the
value of a signal. Is it possible? If yes how?
For example, assume that I have a sin block and I want that its frequency is
determines by the value of a signal. ( for example when the value of this
signal is 2, sin generate a 2K sin) How can design such model?
Best regards
Hi, I don't have time to try this out but I have a couple of
suggestions. You should first turn off the 'Inline parameters'
optimization in the model's Configuration Parameters.
What you can do is create a variable in the workspace; let's say
'sineFreq' and type that into the frequency field of the sine block.
Now, compute the desired frequency value using the other signal and use
a To Workspace block to change the value of sineFreq in the workspace.
You must always ensure that that variable exists in the workspace
before running the model. You can use assignin and the model's InitFcn
callback to do this.
HTH,
Ashish.
Ok, I did try it out and it doesn't work. What I figured out was that
once you change the workspace variable you need to do an update diagram
for Simulink to read the new value. So another solution I can think of
is to run your simulation using a script, search documentation for
'SimulationCommand'; you could start the simulation and step through
it, check sineFreq after every step and if the value has changed then
do an update diagram. This might be really slow; hopefully someone else
will have a better solution.
Also, if you only want to do this for the sine block then you can just
use the Use External Signal option to change the frequency as desired.
Thanks for your help. I couldn't find any information on external signal and
how I can use it. Where can I find this information?

Regards
s***@gmail.com
2006-05-21 04:50:08 UTC
Permalink
If you already know the relationship between the signal value and the
sine frequency, you can use these following blocks : clock block ( for
the time vector), , if/while/for action subsytem block to generate the
frequency, gain block for frequency and time vector mulitplication and
feed the output of the gain block to a sine trignometric function
block.

The action subsystem will be implementing the relationship between
signal value and frequency. While implementing the subsystem block
designate it as an "atomic". (refer to help on this). There might be
other implementation schemes as well.

Regards
ma
2006-05-21 09:33:21 UTC
Permalink
Post by s***@gmail.com
If you already know the relationship between the signal value and the
sine frequency, you can use these following blocks : clock block ( for
the time vector), , if/while/for action subsytem block to generate the
frequency, gain block for frequency and time vector mulitplication and
feed the output of the gain block to a sine trignometric function
block.
The action subsystem will be implementing the relationship between
signal value and frequency. While implementing the subsystem block
designate it as an "atomic". (refer to help on this). There might be
other implementation schemes as well.
Regards
Thanks for your suggestion.

I couldn't understand how to implement but the main question is:
Is it a general solution? For example it is the way that I can change every
tuneable parameter in every block or it is just a solution for this specific
example?

regards
s***@gmail.com
2006-05-21 19:22:13 UTC
Permalink
It is a solution for this specific example.
kia
2006-05-24 05:59:10 UTC
Permalink
Post by ma
I want to change the parameter of a block during simulation based on the
value of a signal. Is it possible? If yes how?
You have discovered just how limited graphical programming can be, and
to paraphrase:

"...as a simulation tool, it is often ridiculous to create dozens of
graphical objects to perform a task that can be stated in a single
sentence."

you'll be into graphical spaghetti programming without even doing
something of substance. Here's a link to an interesting article - not
just for rocket scientists anymore - that may help you guide where, you
want to go trw... http://www.sdynamix.com/sim.html
Physioneer
2006-05-25 19:55:21 UTC
Permalink
I change parameter in a simulink toolbox with help of m-file. You can
run simulink models from m-files (command is: sim filename). Suppose,
you have a resistance block in your simulink model. You have to type
a a numeric value in that resistance block to run the model. Now you
want to try different values (e.g., 1,2,3,4 and 5) of that resistance
and run your model. Type a letter or word (say in this case, R) in
that block, instead of the numberic value of the resistance. Now
create a m-file in Matlab like the following;

R = 1;
sim resistor.mdl (assuming resistor.mdl is your simulink file)

Save and run that m-file. R will be there in the workspace with a
value of 1. Since you have put R in the resistance block, it will
take 1 as the value of that resistance and Matlab will run the
simulink file.
You can use FOR loop and many other things in that m-file to modify
value of R and re-run your simulink model.
Hope it helps.
Post by ma
Hello,
I want to change the parameter of a block during simulation
based on the
value of a signal. Is it possible? If yes how?
For example, assume that I have a sin block and I want that its frequency is
determines by the value of a signal. ( for example when the value of this
signal is 2, sin generate a 2K sin) How can design such model?
Best regards
vinch
2006-05-25 20:19:49 UTC
Permalink
Post by ma
Hello,
I want to change the parameter of a block during simulation
based on the
value of a signal. Is it possible? If yes how?
For example, assume that I have a sin block and I want that its frequency is
determines by the value of a signal. ( for example when the value of this
signal is 2, sin generate a 2K sin) How can design such model?
Best regards
Take a look at the solution posted at the following URL:

<http://www.mathworks.com/support/solutions/data/1-15W7Y.html?solution=1-15W7Y>
Loading...