Simulink Data Cube Accumulation
조회 수: 18 (최근 30일)
이전 댓글 표시
Hello, I am fairly new to Simulink & have been trying to find an answer to my question online and on the Mathworks forums to no avail.
I have a Simulink model where I'd like to accumulate samples into a data matrix (for matrix/block processing later on). I have been using the "Data Store Memory" to allocate memory for this data matrix. To illustrate with an example: I have discrete samples flowing through my model, I'd like to create a data matrix which is 1000 samples x 10 data vectors. I have a counter which counts up to 1000, at which point it increments a column counter.
Currently I am using a buffer object (from DSP toolbox) with a buffer size of 1000, and I'm feeding that into a "Data Store Write" block with an element assignment of "dataMatrix(:,1)". There are a few issues with this: 1. The "Data Store Write" block does not appear to be able to handle a buffered input; 2. Even if it did handle the buffered input, I would only ever be assigning column 1 of the dataMatrix, I can't figure out a way to dynamically alter the column of the "Data Write Store" element assignment.
Does anyone know how to accomplish what I'm trying to do? I'm trying to avoid using a Matlab function block if at all possible given that I am eventually deploying this on hardware.
Please let me know if you have any questions or clarifications!
Thank you in advance,
Chris
댓글 수: 0
답변 (1개)
Brian Neiswander
2015년 8월 19일
One approach is to use the "Buffer" block to create data frames and then use a "To Workspace" block to write the frames to a workspace variable. I created a simple example shown in the figure below.
In this example, a discrete "Sine Wave" block is used to generate a signal with a sample time of 0.01. The output is buffered into frames of size 1000x1 using a "Buffer" block. The output of the "Buffer" block is passed to a "To Workspace" block that is set to save the 2-D signal as a "3-D array (concatenate along third dimension)".
After running the simulation, a workspace variable named "simout" is created:
>> whos simout
Name Size Bytes Class Attributes
simout 1000x1x11 88000 double
You can see above that the "simout" variable is of size 1000x1x11. The first frame contains the buffer's initial condition. The subsequent 10 frames each contain 10 seconds of data.
Also, note that you can use "MATLAB Function" blocks and still deploy to hardware. You need to make sure that the compilation directive:
%#codegen
is present in your function definition as:
function y = fcn(u)
%#codegen
y = u;
See the link below for more information about the compilation directive:
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!