필터 지우기
필터 지우기

Storing the clock time into a vector in simulink

조회 수: 13 (최근 30일)
Muthappa
Muthappa 2011년 9월 26일
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
Fangjun Jiang
Fangjun Jiang 2011년 9월 26일
What is your goal? There might be alternatives other than using the embedded matlab function block.
Muthappa
Muthappa 2011년 9월 26일
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!!

댓글을 달려면 로그인하십시오.

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 9월 26일
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
Fangjun Jiang
Fangjun Jiang 2011년 9월 26일
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 2011년 9월 27일
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!!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by