Multidimensional data load in simulink

3 次查看(过去 30 天)
I have matlab data structures where for every time stamp (frame in our case) , there are multiple data points (rows). Every data point is having multiple column/attributes.
Simulink takes time versus signal data. How can I re-structure my data to fit to simulink requirements. Am I missing something here ?

回答(1 个)

Sharad
Sharad 2023-6-15
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.

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by