Trouble making a parameter sweep for Simulink
30 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Salvador
am 5 Dez. 2025 um 18:50
Kommentiert: Salvador
am 6 Dez. 2025 um 11:56
Hi, I'm trying to make a parameter sweep program that fetches different output values of two logged signals for different values of a resistance in a Simulink circuit. When I simulate said circuit manually, inside Simulink, I get the expected results and everything works like it should. However, to realize said parameter sweep I must write an appropriate code in an m. file, and after a couple hours of research I was able to come up with the following:
model = 'simulacion_redes_bipuerta';
load_system(model)
R = linspace(0.1,5,10);
I = zeros(1,10);
V = zeros(1,10);
for k = 1:length(R)
set_param(['simulacion_redes_bipuerta','/Load'],'Resistance',num2str(R(k)));
sim(model);
I(k) = out.logsout{1}.Values.Data(end);
V(k) = out.logsout{2}.Values.Data(end);
end
P = V.*I;
plot(R,P)
The problem with this script is that when running it the 'out' object does not get saved to my workspace (nor any other kind of output variable), and thus I get an error saying "Unable to resolve the name 'out.logsout'." I have no idea why this could be happening. My Simulink model settings are set to default, by which a "Single simulation output" named 'out' should be saved to my workspace after each simulation. Any help would be very appreciated!
Edit: It seems that the 'out' variable gets saved only when I manually run the simulation inside Simulink itself, but then again this isn't enough for me as I'm supposed to perform the parameter sweep across at least 100 different values. Therefore, the problem seems to lie in the sim() command, which for some reason isn't simulating the model correctly.
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
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!