Hi,
In order to restructure your data to fit Simulink requirements, you can follow these steps:
- Ensure that the multidimensional data is stored in a suitable MATLAB data format (eg- M x N matrix).
- Add a MATLAB function block to the Simulink model (restructuring of data can be done in this block).
- Adjust the input and output ports.(for eg - if there are M timestamps and N data points for each timestamp, the input port can be set to 'M x N' and output port to 'T x 1', where T = M * N.
% the input and output sizes can be calculated
[M, N] = size(data);
T = M * N;
- Code the MATLAB function:
function out = restructureData(data)
% reshape the vector to T x 1 matrix
values = reshape(data, [], 1);
end
- Connect the "From Workspace" block to the input port of the MATLAB Function block, and connect the output port of the MATLAB Function block to the rest of your Simulink model.
- Configure the "From Workspace" block to load the multi-dimensional data. Set the "Data Type" as a matrix and provide the appropriate variable name, such as 'data', in the "Variable name" field.