Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: Store Historical Data in Level2 M Function Dwork Vector

$
0
0
The code in your original post does what it is supposed to do.
The output will only be non-zero when the DWork vector is equal to 10 (and there's a one period time delay, so the non-zero occurs at the 11th period).

Here you are defining a single (scalar valued) work vector
> block.Dwork(1).Dimensions = 1;

and here
> block.Dwork(1).Data = 0;
and here
> block.Dwork(1).Data = block.InputPort(1).Data;
you are assigning a single number into the work vector.

So why why here
> I thought that at the 5th sample time, Dwork would be [1, 2, 3, 4, 5].

would you expect it to be a vector?

If you want a vector then you need to define it using
block.Dwork(1).Dimensions = 256; %or whatever length of vector you want

And then use standard MATLAB matrix indexing to put elements into the vector,
block.Dwork(1).Data(idx) = newValue;
where idx is an integer index into the matrix defining what element to replace.

Note however that you cannot dynamically resize a Work Vector so you need to define its size during initialization.
If you want to store all historical values then you'll possibly need a very large matrix.

Phil.

Viewing all articles
Browse latest Browse all 19628

Trending Articles