Simulink: Input port not imported
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all,
I have the following Simulink model:
I import the values thtough a script, here's an extract for the first port:
input_PGCT.time = [];
input_PGCT.signals.values = double(94.43);
input_PGCT.signals.dimension = 1;
I then call my model through:
t_stop = 5;
T_s = t_stop/1000;
options = simset('SrcWorkspace','current', 'fixedstep', T_s) ;
sim('test_In_To_Switch.slx',t_stop, options)
But the scope for the 1st input port shows me the variable is not correctly imported and stays at 0:
I noticed that in Simulation > Model Configuration Parameters > Data Import/Export > Load from Workspace, the input was [t,u], unchanged. I tried to change it to :
But then I get an error:
Invalid structure-format variable specified as external input in 'test_In_To_Switch'. Time and data values must have the same number of rows
Would anybody know how to solve this ?
Thanks in advance
0 Kommentare
Antworten (1)
Samay Sagar
am 29 Feb. 2024
Simulink requires the time vector and the signal values to be of the same length. Since you're trying to input a constant value, the time vector needs to be explicitly defined to match the duration of your simulation.
Here's how you can construct your input structure to meet these requirements:
t_stop = 5;
T_s = t_stop/1000;
input_PGCT.time = (0:T_s:t_stop)';
input_PGCT.signals.values = repmat(double(94.43), length(input_PGCT.time), 1);
input_PGCT.signals.dimensions = 1;
In this revised approach, “input_PGCT.time” is a column vector that matches the simulation timeframe, and “input_PGCT.signals.values” is a column of the constant value 94.43, replicated to correspond with each time step. This ensures that the time and signal values have the same number of rows, satisfying Simulink's requirements.
After defining your input structure, you'll need to update the Model Configuration Parameters to use “input_PGCT” as the external input. To do this, navigate to Simulation > Model Configuration Parameters > Data Import/Export and set the “Input” field to “input_PGCT”.
Since you are trying to import multiple signals in your model, here is a concise way to set up your structure for importing multiple signals into different “inports” with a shared time array for your Simulink simulation:
% Define the simulation stop time and sampling time
t_stop = 5;
T_s = t_stop / 1000;
% Create a time vector for the entire simulation duration
time_vector = (0:T_s:t_stop)';
% Initialize the input_signals struct with the shared time vector
input_signals = struct();
input_signals.time = time_vector;
% Define the values and dimensions for each signal
input_signals.signals(1).values = repmat(double(94.43), length(time_vector), 1);% input_PGCT
input_signals.signals(1).dimensions = 1;
input_signals.signals(2).values = repmat(double(50.00), length(time_vector), 1);% input_RMEP
input_signals.signals(2).dimensions = 1;
input_signals.signals(3).values = repmat(double(75.00), length(time_vector), 1); %input_TGGT
input_signals.signals(3).dimensions = 1;
% Set up simulation options
options = simset('SrcWorkspace', 'current', 'fixedstep', T_s);
% Run the simulation
sim('test_In_To_Switch.slx', t_stop, options);
Similarly, you will need to update the Model Configuration to use “input_signals” as external input.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!