Get calculated output arguments when an error is thrown

Say I have the following function, that calculates the transpose and inverse of a matrix:
function [At, Ai] = TransposeAndInverse(A)
At = A.';
Ai = inv(A);
end
and I call it with the following argument:
A = [1,2,3;4,5,6];
[At, Ai] = TransposeAndInverse(A);
I get an error, since A is not invertible (as expected). However, inside the function, At was calculated successfully.
My question is - can I somehow extract the output arguments that were calculated before the error was thrown using a try catch statement? And if so, how?
Thanks

 채택된 답변

Walter Roberson
Walter Roberson 2023년 2월 21일

0 개 추천

No, the function would have to be designed to use try/catch itself. Once an error is thrown and the function has returned all of its internal variables are gone.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Functions에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2023년 2월 21일

답변:

2023년 2월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by