How do I define scalar, vector and matrix data in the workspace as a struct to load into multiple root-level inports in a Simulink model?

2 ビュー (過去 30 日間)
I am following the workflow in the "Loading Data Structures to Root-Level Inputs" section of the MATLAB Documentation titled Load Data to Root-Level Input Ports to define inputs to multiple root-level inports in my Simulink model, each of which has different dimensions. 
In particular, I have one inport with dimensions "1" , one with dimensions "3", and one with dimensions "[2 3]". The workflow that I'm currently doing is leading to this error:
Error loading external input data into root-level Inport <inportName> in model <modelName>.
How do I set this up? 

採用された回答

MathWorks Support Team
MathWorks Support Team 2025 年 11 月 5 日
The below script shows how to set it up with the correct dimensions in the .values fields, with the data in the workspace stored in a variable named "input_data".
For a sample time "dT" of 0.1, and number of samples "N" set to 100, this script demonstrates how to set the relevant fields of "input_data" for input data that is a scalar, 1x3 vector, and 2x3 matrix respectively. 
For demonstration purposes, the values of the inputs, "val", is set to 0 at all timesteps, but you would modify "val" to contain your desired input values, making sure that it remains the same length as the "input_data.time" vector. 
dT = 0.1; % Sample time
N = 100; % Number of samples
input_data.time = dT*(0:(N-1))';
time_vec = input_data.time;
% Input is a scalar
input_data.signals(1).values = 0*time_vec; % Modify this as desired to your input values
input_data.signals(1).dimensions = 1; % feeds an input port with dimensions = -1
% Input is a 1x3 vector
val = zeros(N,3); % N x 3 matrix where N is number of timesteps.
input_data.signals(2).values = val; % Modify this as desired to your input values
input_data.signals(2).dimensions = 3; % feeds an inport port with dimensions = 3
% Input is a 2x3 matrix
val = zeros(2,3,N);
input_data.signals(3).values = val; % Modify this as desired to your input values
input_data.signals(3).dimensions = [2 3]; % feeds an inport port with dimensions = [2 3]
Then, prior to running your model, you should: 
-In the Configuration Parameters, set the "Input" field to "input_data": 
Once this data is defined as described, you should be able to run your model as expected. 

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge-Scale Modeling についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by