Try and Catch for multiple conditions

조회 수: 29 (최근 30일)
Jason
Jason 2022년 4월 6일
편집: Les Beckham 2022년 4월 6일
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?

답변 (2개)

David Hill
David Hill 2022년 4월 6일
if condition1
%do
elseif condition2
%do
elseif condition3
%do
elseif condition4
%do
elseif condition5
%do
elseif condition6
%do
end
  댓글 수: 1
Jason
Jason 2022년 4월 6일
편집: Jason 2022년 4월 6일
Sorry, by condition its really checking for camera properties (using the image acquisition toolbox).
I.e
Name = src.DeviceName
Model = src.Model
Bin = src.BinningHorizontal
Etc. But sone of these properties dont exist for some cameras, so i currently surround then with try and catch.

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


Les Beckham
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...

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for USB Webcams에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by