Trouble making a parameter sweep for Simulink
12 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Paul
21 minutes ago
Try
out = sim(model);
More generally check out Simulink.SimulationInput and Optimize, Estimate, and Sweep Block Parameter Values and Running Multiple Simulations and linked doc pages for alternative approaches if interested.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!