Divide by Zero Warning

23 ビュー (過去 30 日間)
Kayla McCarty
Kayla McCarty 2019 年 2 月 21 日
回答済み: Walter Roberson 2019 年 2 月 21 日
Hello,
I am trying to generate a warning when matlab divides by zero.
Running the following code:
warning on MATLAB:divideByZero
1/0
still does not generate an error.
I cannot find any official documentation about this feature being phased out, and it doesn't throw an error or anything when I try to turn the warning on. Does anybody have any suggestions as to how to get a warning when you divide by 0?
Thanks in Advance!

採用された回答

Adam Danz
Adam Danz 2019 年 2 月 21 日
At some point matlab got rid of this warning so there's no way to turn it on with recent versions of Matlab.
If you need this warning for a particular function or script, you could write a simple conditional statement that throws a warning when the denominator is equal to zero.
Here's an example.
p = n/d;
if any(d(:) == 0)
warning('Divide by zero')
end

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 2 月 21 日
R2009b started phasing it out.
There might not have been documentation that it is now gone completely, but it was gone by R2011a at latest.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by