Filter löschen
Filter löschen

Storing the clock time into a vector in simulink

13 Ansichten (letzte 30 Tage)
Muthappa
Muthappa am 26 Sep. 2011
Hi,
I wanted to know how can I use embedded matlab block in simulink to store the clock time into a vector?
I am using time clock as the input to embedded matlab block and trying to store that in a vector variable which is the output of embedded matlab block? Is this a right way to do, if not how else can I do it?
It would be of great help, if you could suggest or advise me on how to do it.
Thanks!!
  3 Kommentare
Fangjun Jiang
Fangjun Jiang am 26 Sep. 2011
What is your goal? There might be alternatives other than using the embedded matlab function block.
Muthappa
Muthappa am 26 Sep. 2011
Thank you very much for your responses. I really appreciate your help. I cannot use concatenate vector for my purpose. My goal is to calculate the area of a plot obtained in my simulink for which I am trying to use trapz command in embedded matlab block.
Since the plot is a curve which is generated in time, in order to use it in trapz I have to store both the clock time and output from the plot in different vectors.
To be more specific:
For example:
If the simulation time is 200 seconds and a variable which varies with time to give an curve is plotted during this simulation.
I wanted to calculate the area of that curve between the time 50 and 150 seconds based on which I need to take further action. In order to do that I am trying to use trapz command in an embedded block.
The input to this block will be 1. Clock time (t) 2. Output from the plot (v) which is a variable which varies with time to form a curve.
I am trying to use trapz command in the following format to find its area.
A1 = trapz(t(50:150),v(50:150));
But I am getting out of bound error as both the inputs are of single dimension and they have not been stored as a vector. So, I want to store each of the inputs into a vector during my simulation so that after 150 seconds is complete, area will be calculated with trapz command.
Thanks!!

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Fangjun Jiang
Fangjun Jiang am 26 Sep. 2011
For this task, I recommend not to use the Embedded MATLAB Function block. As you can see, if your simulation just started for a short period of time, you won't be able to run trapz(t(50:150),v(50:150)) because the 150th data point is not available yet. The Embedded MATLAB Function block in the Simulink model will typically run at every time step.
You can use the "To Workspace" block to log the data. Using the 'Structure with Time" save format will log the time and value at once. Once the simulation is done and the data is logged, you can post-process the data using trapz().
  3 Kommentare
Fangjun Jiang
Fangjun Jiang am 26 Sep. 2011
For that, maybe you can play with the persistent declaration of the variable. doc persistent
I am still thinking this approach is awkward. Can't you put an Integrator block inside a triggered subsystem and trig the subsystem at t=150 seconds.
Muthappa
Muthappa am 27 Sep. 2011
Thank you for your reply. I am using the persistent variable method now. I am able to store the clock time with that. But there is one more variable in my simulink which varies with time and have to store that in a vector too..Facing problems with it as of now. I hope I succeed in that soon.
I really appreciate your time & help,
Thanks!!

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by