error handling - Matlab - how to catch warning released by cp2tform function -
i have set of n
sets of 2d points , want parse these n
sets in order find affine transformation(translation, rotation, scaling including reflexion) set q
of 2d points.
in order so, applying matlab function cp2tform
. however, there scenarios when function gives me warning similar 1 illustrated bellow:
warning: condition number of 117632159740.8394. > in maketform>validate_matrix @ 328 in maketform>affine @ 163 in maketform @ 129 in cp2tform>findaffinetransform @ 265 in cp2tform @ 168
in these cases, transformation matrix identified cp2tform
function not apply real transformation between 2 sets of 2d points. how can catch these situations in order skip them? matlab function or code should introduce in order catch these situations in order able skip or handle them?
handle warning:
as explained here, convert specific warnings errors, , trap inside try/catch block.
here example on how handle specific warning (inverting singular matrix):
% turn specific warning error s = warning('error', 'matlab:nearlysingularmatrix'); %#ok<ctpct> % invoke code trapping errors try = [1 2 3; 4 5 6; 7 8 9]; b = inv(a); disp(b) catch me if strcmp(me.identifier, 'matlab:nearlysingularmatrix') fprintf('warning trapped: %s\n', me.message); else rethrow(me); end end % restore warning state warning(s);
suppress warning:
of course if want suppress warning message, query last warning issued using:
[msgstr, msgid] = lastwarn;
(or use syntax @benoit_11 showed), turn off until temporarily inside function:
% turn off s = warning('off', msgid); % ... % restore state warning(s);
Comments
Post a Comment