Try and Catch for multiple conditions

29 visualizzazioni (ultimi 30 giorni)
Jason
Jason il 6 Apr 2022
Modificato: Les Beckham il 6 Apr 2022
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?

Risposte (2)

David Hill
David Hill il 6 Apr 2022
if condition1
%do
elseif condition2
%do
elseif condition3
%do
elseif condition4
%do
elseif condition5
%do
elseif condition6
%do
end
  1 Commento
Jason
Jason il 6 Apr 2022
Modificato: Jason il 6 Apr 2022
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.

Accedi per commentare.


Les Beckham
Les Beckham il 6 Apr 2022
Modificato: Les Beckham il 6 Apr 2022
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...

Categorie

Scopri di più su MATLAB Support Package for USB Webcams in Help Center e File Exchange

Tag

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by