フィルターのクリア

flag an error message when a scalar is complex

2 ビュー (過去 30 日間)
msh
msh 2015 年 5 月 31 日
コメント済み: Nobel Mondal 2015 年 5 月 31 日
Hi,
I would like to include in my algorithm an error message where it will tell me that a scalar is complex. So for example I would like to implement in Matlab the following idea
if scalar == complex number
show error message
end
How I can implement this Matlab ?
Thanks

採用された回答

Nobel Mondal
Nobel Mondal 2015 年 5 月 31 日
if ~isreal(num)
error('This is a complex number.')
end
  2 件のコメント
msh
msh 2015 年 5 月 31 日
編集済み: msh 2015 年 5 月 31 日
Thanks for the quick response. One clarification. In the ~isreal(num) , num is the relevant scalar, correct? can this be also extended to matrices ?
Nobel Mondal
Nobel Mondal 2015 年 5 月 31 日
Yes, num is the scalar which you want to check for.
For matrix:
>> A = [ 1 2 3; 4 5+6i 7];
>> isreal(A)
ans =
0
>> isreal(A(1,1))
ans =
1
>> isreal(A(2,2))
ans =
0
Hope this clear things up for you.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by