Trouble making a parameter sweep for Simulink
19 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!