condition if command is possible or not

2 ビュー (過去 30 日間)
Hbro
Hbro 2017 年 2 月 21 日
回答済み: Rik 2017 年 2 月 21 日
I want to create a loop that runs through several matrices(A(:,:,n)) and create a condition;
for i=1:length(A)
if inv(A(:,:,i) "is possible"
iv=inv(A(:,:,i));
elseif
disp('impossible')
end
end
how do i syntax "if command is possible" or impossible?

採用された回答

Rik
Rik 2017 年 2 月 21 日
In this case there is probably a function that will tell you if a matrix is invertable, but there is a more general solution. You can use try and catch to do what the names suggest: try some code and catch the error.
for i=1:length(A)
try
iv=inv(A(:,:,i));
catch
disp('impossible')
end
end
Or:
try
for i=1:length(A)
iv=inv(A(:,:,i));
end
catch
disp('impossible')
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by