sim(simIn) gives error saying all the runs have an error
5 次查看(过去 30 天)
显示 更早的评论
% set_param('fl_name/Speed_sweep','Value','Spd')
Spd = 100;
%% Speed Array
Speed = zeros(1,5001);
len = numel(Speed);
q=0;
for s = 1:len
Speed(1,s) = q;
q = q + (1/(len-1));
end
Trq_inst = zeros(1,401);
len_trq = numel(Trq_inst);
Trq_ref =1;
clear simIn
clear simOutputs
for t = 1:(len_trq)
Trq_inst(1,t)= Trq_ref;
for i = 1:len
simIn(i) = Simulink.SimulationInput('fl_name');
simIn(i) = setBlockParameter(simIn(i),'fl_name/Speed_Sweep','Spd',Speed(i));
end
simOutputs = sim(simIn);
Trq_ref = Trq_ref - (1/(len_trq-1));
end
1 个评论
Walter Roberson
2024-8-18
It won't make a difference to the error, but I would recommend rewriting the code to be something like
len = 5001;
Speed = linspace(0, 1, len);
with no q or for s loop. It would be neater and more compact.
回答(1 个)
Walter Roberson
2024-8-18
编辑:Walter Roberson
2024-8-18
simIn(i) = setBlockParameter(simIn(i), 'fl_name/Speed_Sweep', 'Spd', string(Speed(i)));
That is, block parameter values must (usually) be strings or character vectors.
14 个评论
Paul
2024-8-31
Yes 2020b is indicated on this page. But as you've pointed out the CaptureErrors input is valid for 2020b, yet the error message in the attachment to this comment indicates that CaptureErrors is an invalid input to the sim command. OTOH, that attachment also shows the same command run from the command line three times in a row, and the third time results in a different error than the first, which is strange. Also, the error messages don't really look like typical error messages. Maybe the sim command is shadowed? Strange results ....
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!