Borrar filtros
Borrar filtros

Getting out a result for every loop

4 visualizaciones (últimos 30 días)
Mohammed Flaga
Mohammed Flaga el 5 de Jun. de 2022
Respondida: Ramtej el 7 de Sept. de 2023
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
Unable to resolve the name 'out.logsout.getElement'.
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!

Respuestas (1)

Ramtej
Ramtej el 7 de Sept. de 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!

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by