Saving vectors for consecutive timesteps and turn them into an array
조회 수: 3 (최근 30일)
이전 댓글 표시
I have built a Simulink model which has 5 input signals. Once the scalar values get normalized I turn these 5 signals into a vector by using the Mux Block.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/832265/image.png)
My LSTM (Block: Stateful Predict) needs a numeric array as an input. This works perfectly fine when I am using the constant block with predefined values. However it would not accept a vector as it needs a timeseries.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/832275/image.png)
What would be the best way to save 10 vectors from 10 consecutive timesteps and turn them into an array in order to give my neural network a valid input? I did not find suitable Simulink blocks, so maybe it can only work with a Matlab function block?
Thanks a lot in advance!
Kind Regards
댓글 수: 0
답변 (1개)
Samay Sagar
2024년 2월 23일
To provide a sequence of vectors as input to the LSTM 'Stateful Predict' block in Simulink, you can accumulate the vectors over time within a MATLAB Function block and transform it to a “timeseries”.
Here’s how you can implement this:
Add a MATLAB Function block to your Simulink model to store and update a buffer that accumulates vectors from consecutive timesteps. You can now use this output as input to your “Stateful Predict” block.
function timeseriesData = inputToTimeSeries(u)
% u: Current input vector from the Mux block
% Define persistent variables for the buffer vector
persistent buffer;
buffer = [buffer ;u];
% Convert the buffer to a timetable
timeseriesData = array2timetable(buffer, 'TimeStep', seconds(0.2));
end
Read more about “array2timetable” here:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!