MATLAB: This MATLAB code for try catch not works properly.

Computer Vision Toolboxerrormatch

try
boxPairs = matchFeatures(data1, data2);
catch
if boxPairs == 0
disp('there was an error')
else
plot(x,y)
end
end
This is the part of my program.
When i run above code, it completely runs without any error. But no operation is happening,. I checked my workspace. I am getting
boxPairs = 0
but i am not getting anything as disp in command window. What changes needed in program.?

Best Answer

Hi Nimisha,
boxPairs can never be equal to 0. boxPairs is an M-by-2 matrix containing the indices of matched features. However, if no matches were found, then boxPairs is empty. So your error checking should look like this:
boxPairs = matchFeatures(data1, data2);
if isempty(boxPairs)
disp('No matches found')
else
plot(x,y)
end
The error you are getting comes from the estimateGeometricTransform, because it is getting empty points, because boxPairs was empty.