how to record and use the history of a variable in simulink

I am using Simulink for my project. My project is working in discrete time system. The task required to use more than one previous values of a variable to calculate the next step. Moreover, I want to vary the number of previous values for calculation. How can I do that ?
for example, at time = 100, i have 1~100; at time = 101, i have 2~101; at time = 102, i have 3~102 ; ...
Thanks you very much for help :)

Answers (1)

I don't know if you can change the number of previous steps dynamically. If the number is not large, you can always record the maximum number of previous steps. For example, use five Unit Delay blocks to record the the value of five previous steps. Then, in your calculation, you can decide whether you want to all five of them, or just three previous steps. You can set the coefficient of the 4th and 5th to be zero to achieve that effect.
Or try the Buffer block

6 Comments

Thanks a lot Fangjun. However I need quite a large number of previous steps (about 100 of them). If that is the case, i will need 100 unit delay blocks.
Buffer block works pretty good but not totally what I want. I hope that can work similar to 100 unit delay blocks.
I have tried a block called "Queue". It stores several delay of the system, but I want the values that is stored in the block, instead of the output value.
Queue
http://www.mathworks.com.au/help/toolbox/dsp/ref/queue.html
What do you mean by "but I want the values that is stored in the block, instead of the output value."? To me, the Buffer block accepts one input and gives 100 ouputs which are the previous values. It meets your need. What else are you looking for?
"the values that is stored in the block" I am talking about Queue block not the Buffer block.
About the Buffer block, although it gives 100 output, it gives a lag to the system.
e.g. If there are 200 data and buffer size is 100, you will get 2 set of 100 data.
what I want is like the following
at time = 100, i have 1~100
at time = 101, i have 2~101
at time = 102, i have 3~102
......
I see. Then I hope this "Delay Line" block is what you need.
http://www.mathworks.com/help/toolbox/dsp/ref/delayline.html

Sign in to comment.

Asked:

on 4 Jan 2012

Community Treasure Hunt

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

Start Hunting!