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
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
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
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 CenterFile Exchange 中查找有关 Surrogate Optimization 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by