How to catch warnings?
198 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mr M.
el 19 de Sept. de 2018
Respondida: Geoff May
el 25 de Jul. de 2020
I want to catch Warning: Matrix is close to singular or badly scaled, during a matrix division A/B.
0 comentarios
Respuesta aceptada
Más respuestas (1)
Geoff May
el 25 de Jul. de 2020
You could use the lastwarn function to reset, then check the last warning. Granted this might not work if the warning you are interested in gets overwritten by a subsequent warning that you would rather discard.
% reset the lastwarn message and id
lastwarn('', '');
% call the function that might throw a warning
diceyFunction();
% now if a warning was raised, warnMsg and warnId will not be empty.
[warnMsg, warnId] = lastwarn();
% you can check the warning message or id, or just throw the warning as an error if desired
if(isempty(warnId))
noProblem();
else
error(warnMsg, warnId);
end
0 comentarios
Ver también
Categorías
Más información sobre Error Handling en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!