How to check the type of a variable is logical in MatLab? - islogical -- MatLab
How to check the type of a variable is logical in MatLab? - islogical -- MatLab
How to check the type of a variable is logical in MatLab?
[Ans]
islogical
[description]
<answer>=islogical(<b1>)
When <b1> is a logical, it returns true.
Otherwise, it returns false.
[NOTE]
Great Importance!!! Please pay a lot of attention on it.
(1)
islogical(1) and islogical(2) will return false because 2 is considered as double type.
(2)
islogical(5<7) will return true because 5<7 is a relational operator.
more details on:
logical
islogical
code
clear
clc
b1=logical(1)
islogical(b1)
b2=logical(0)
islogical(b2)
b3=logical(2)
islogical(b3)
b4=logical([0 1 0 1 2 3])
islogical(b4)
b5=logical('A')
islogical(b5)
b6=logical(['A' 0 0 'B'])
islogical(b6)
%{
%compiler error
%because there is not conversion between struct and logial
s7=struct('a',2)
b7=logical(s7)
islogical(b7)
%}
b8=5
islogical(b8)
b9={2 3 4}
islogical(b9)
b10=true
islogical(b10)
b11=false
islogical(b11)
result:
b1 =
1
ans =
1
b2 =
0
ans =
1
b3 =
1
ans =
1
b4 =
0 1 0 1 1 1
ans =
1
b5 =
1
ans =
1
b6 =
1 0 0 1
ans =
1
b8 =
5
ans =
0
b9 =
{[2]} {[3]} {[4]}
ans =
0
b10 =
1
ans =
1
b11 =
0
ans =
1
Comments
Post a Comment