Getting out a result for every loop
2 views (last 30 days)
Show older comments
Hey guys,
I want to try different PID-Values for my non-linear system in a Simulink-Model and wrote a loop in matlab script.
Ideally I want to get the result of time over pressure for every loop so I can compare the different results, but I don't know how to build the code for that.
for i = 1:10
P(i) = 0-i;
I(i) = -1;
D(i) = 0;
end
for i = 1:10
drucksignal = out.logsout.getElement('out_druck');
t = drucksignal.Values.Time;
druck = drucksignal.Values.Data;
end
sim('Druckprop_Umwandlung_Funktion.slx')
But i´ll always get the Error:
Error using Druckprop_Umwandlung_Script (line 28)
Error due to multiple causes.
Caused by:
Error using Druckprop_Umwandlung_Script (line 28)
Error in port widths or dimensions. 'Output Port 1' of 'Druckprop_Umwandlung_Funktion/Add' has 200 elements. This port does not accept the
dimensions (or orientation) specified by the output signal.
Error using Druckprop_Umwandlung_Script (line 28)
Error in port widths or dimensions. Invalid dimension has been specified for 'Input Port 1' of
'Druckprop_Umwandlung_Funktion/Öffnungsverhalten3'.
Can anybody help?
Many thanks in advance!
0 Comments
Answers (1)
Ramtej
on 7 Sep 2023
Hi Mohammed,
The error you are encountering seems to be related to the dimensions or port widths of the signals in your Simulink model. The error message suggests that there is a mismatch between the dimensions of the output signal from the 'Add' block and the input signal to the 'Öffnungsverhalten3' block in your model.
Make sure that the dimensions of the signals connected to the 'Add' block and the 'Öffnungsverhalten3' block are compatible.
To obtain the time and pressure results for each loop iteration, you need to store the results in arrays or data structures.
% Initialize empty arrays before the loop, and then store the time and pressure values
% inside the loop for each iteration as shown below
timeResults = cell(1, 10);
pressureResults = cell(1, 10);
for i = 1:10
P = 0-i;
I = -1;
D = 0;
sim('Druckprop_Umwandlung_Funktion.slx');
drucksignal = out.logsout.getElement('out_druck');
timeResults{i} = drucksignal.Values.Time;
pressureResults{i} = drucksignal.Values.Data;
end
Hope this answers the question you had!
0 Comments
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!