Try and Catch for multiple conditions
조회 수: 10(최근 30일)
표시 이전 댓글
Hello. If I have say 10 conditions and each one may fail, rather than have a try and catch round each condition, is there a better way where if condtion 1 isnt met, it ignores it and moves onto condition2?
댓글 수: 0
답변(2개)
David Hill
2022년 4월 6일
if condition1
%do
elseif condition2
%do
elseif condition3
%do
elseif condition4
%do
elseif condition5
%do
elseif condition6
%do
end
Les Beckham
2022년 4월 6일
편집: Les Beckham
2022년 4월 6일
Maybe something like this:
if isfield(src, 'DeviceName')
Name = src.DeviceName;
else
Name = 'unknown'; % or, just don't set the Name (leave off the else part)
end
if isfield(src, 'Model')
Model = src.Model;
else
Model = 'unknown';
end
% and so on...
댓글 수: 0
참고 항목
범주
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!