MATLAB Simulink communication in real time

Hi, In my simulink model I am reading a variable's value from MATLAB workspace. Now if I change that variable's value in workspace while simulink is running, then simulink does not get the updated value. It keeps reading the preassigned value. Is there any way by which simulink model can get updated values from MATLAB workspace in real time (without using RT licence or xPC target)
Thanks Mitesh

 Akzeptierte Antwort

Nirmal Gunaseelan
Nirmal Gunaseelan am 9 Aug. 2011

4 Stimmen

One way to tune the parameter based on a change in a variable in the MATLAB workspace is to 'update' the model while it is still simulating (Ctrl+D). What is your use case? Are you controlling the model simulation from another MATLAB script?

10 Kommentare

Fangjun Jiang
Fangjun Jiang am 9 Aug. 2011
Nice. Glad to know that. I just tired and it worked. I didn't know before that you can update the diagram while the simulation is running.
It essentially is the same internal process as your suggestion - when you change a block's tunable parameter in the dialog during simulation, an update automatically happens.
Mitesh Farsodia
Mitesh Farsodia am 9 Aug. 2011
@Nirmal
Yes, I have a GUI and I will be changing that variable's value from GUI. So when I make change on GUI that value goes to MATLAB's workspace and simulink model has to read that value from workspace.
@Mitesh
Good. In that case, you could add an update command to your model in the callback in addition to changing the variable in the workspace. You could use options 12, 13 or 14 in this command line functionality page - http://www.mathworks.com/support/tech-notes/1900/1903.html
Mitesh Farsodia
Mitesh Farsodia am 9 Aug. 2011
@Nirmal
Thanks, I will try these options and will let you know.
Arnaud Miege
Arnaud Miege am 9 Aug. 2011
I would use the set_param option to change the value of block directly rather than change the value of a parameter in the base workspace.
Mitesh Farsodia
Mitesh Farsodia am 9 Aug. 2011
@Nirmal and Arnaud
I am trying the syntax
set_param('simulinkmodel/blockname','variable','update')
it's not updating automatically, also when I try ctrl+d it doesn't update. Please correct me if I am making any mistake.
Thanks
Fangjun Jiang
Fangjun Jiang am 9 Aug. 2011
It is set_param(YourModelName,'simulationcommand','update').
Make your model your current active window, press Ctrl+D, it should update.
Mitesh Farsodia
Mitesh Farsodia am 9 Aug. 2011
Thanks Frangiun for your suggestion.
When we do this,it tries to update whole simuling model. I have GT power link in my simulink model and when I tried to update some particular block in my simulink model, it updates that particular block and stops the simulation after that. I am assuming at the same moment it is also trying to update that GT poer block, which stops the simulation. Can we update any particular block name without affecting other blocks in model.
Fangjun Jiang
Fangjun Jiang am 9 Aug. 2011
When the model is updated, it is updating the whole model. You need to re-think what you really want. All the approaches talked about above will cause the model to pause, update and then continue. You could leave the simulation continue running while you change the gain of a Gain block, for example. Try that and come back with your true intent.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (4)

Andreas Goser
Andreas Goser am 9 Aug. 2011

1 Stimme

Many people with this description look for a way that is actually an artificial slowdown of Simulink, so that it is running approximately in sync with real time.
The are solutions on FileExchange for that, e.g. this one
Fangjun Jiang
Fangjun Jiang am 9 Aug. 2011

0 Stimmen

Use a Constant block in your Simulink model. While your simulation is running, you can double click the Constant block and change its value. The simulation will pause and then continue with the new Constant block value.
Dharmendra singh
Dharmendra singh am 6 Feb. 2012

0 Stimmen

One way to tune the parameter based on a change in a variable in the MATLAB workspace is to 'update' the model while it is still simulating (Ctrl+D). What is your use case? Are you controlling the model simulation from another MATLAB script?
satisfiefd with reply but not so much

1 Kommentar

Kaustubha Govind
Kaustubha Govind am 6 Feb. 2012
Dharmendra: Perhaps you could provide more information on how Nirmal's answer did not help you? The answer is clear and complete as far as I can see.

Melden Sie sich an, um zu kommentieren.

Tan Phat Nguyen
Tan Phat Nguyen am 10 Mai 2018

0 Stimmen

Sensor 1 (pressure sensor attached to bottom of tank 1) connects to Pin 0 Arduino Uno Sensor 2 (pressure sensor attached to bottom of tank 2) connects to Pin 2 Arduino Uno When running individually, the Volt value and water level return are correct reality. But when running both Volt = 0, water level = 0. So how do I read at the same time two analog values? Thank you

Kategorien

Mehr zu Simulink finden Sie in Hilfe-Center und File Exchange

Produkte

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by