a test to exclude inf and nans from pinv(...) doesn't work

3 ビュー (過去 30 日間)
genevois pierre
genevois pierre 2018 年 9 月 26 日
コメント済み: genevois pierre 2018 年 9 月 26 日
Hello,
having this error :
Error using svd
Input to SVD must not contain NaN or Inf.
Error in pinv (line 29)
[U,S,V] = svd(A,0);
I tried to add this test before calling pinv(gradVcpr) :
if any(isnan(gradVcpr) | ~isfinite(gradVcpr)) % Error : gradVcpr is NaN or infinite
......
return % stop executing the function before call to pinv
end
But the test doesn't work : I still have the same error. Can somebody help me ?
Thank you !

採用された回答

Walter Roberson
Walter Roberson 2018 年 9 月 26 日
if any(isnan(gradVcpr(:))) || any(~isfinite(gradVcpr(:))))
You were missing the fact that any() is a matrix operation that processes only the first non-scalar dimension. Your code was equivalent to
if all(any(isnan(gradVcpr) | ~isfinite(gradVcpr)))
but that was false for some of the columns so the all() failed.
  1 件のコメント
genevois pierre
genevois pierre 2018 年 9 月 26 日
thank you : it works now !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by