How can i force a new simulation if there is a warning

조회 수: 3 (최근 30일)
Bastien Forcione
Bastien Forcione 2020년 7월 9일
댓글: Jesús Zambrano 2020년 7월 15일
Hello, I'm doing a lot of simulations on simulink, and i want to stop and skip the simulations when there is a warning. Is there a way to do it ?
This is the code i tried for the moment, but it doesn't skip the simulation, which takes a lot of time.
for p = 600 : 25 : 1600
for d = 250 : 10 : 300
for i = 0 : 2 : 20
try
Kp = p*eye(6);
Kd = d*eye(6);
Ki = i*eye(6);
sim controle_simple
catch ME
continue
end
% some code to save data
end
end
end

채택된 답변

Jesús Zambrano
Jesús Zambrano 2020년 7월 15일
Hi,
The commands try/catch are used for executing statements and catch errors messages not warning messages.
Since getting a warining can still allow you to run the model, you have to catch the specific warning message and include a 'break' in your for-loop.
A way to catch the warning message is by looking at the following variable when running a model:
ans.SimulationMetadata.ExecutionInfo.WarningDiagnostics.Diagnostic.identifier
For example, when a model has a unconnected outport, the value of this variable is
Simulink:Engine:InputNotConnected
Then, your code will include something like:
if (strcmp(ans.SimulationMetadata.ExecutionInfo.WarningDiagnostics.Diagnostic.identifier,'Simulink:Engine:InputNotConnected'))
break
end
Hope it helps!
  댓글 수: 4
Bastien Forcione
Bastien Forcione 2020년 7월 15일
It works ! Thanks a lot !
Jesús Zambrano
Jesús Zambrano 2020년 7월 15일
Glad to hear that! All the best!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by