des*_*ons 1 binary matlab boolean
我试图在Matlab中使用二进制数的组件作为布尔值.不幸的是,他们没有像我期望的那样行事.以下面的代码为例:
for x = dec2bin(0:1)'
x(1) % the leading bit of x
if logical(x(1))
disp('yes')
else
disp('no')
end
end
Run Code Online (Sandbox Code Playgroud)
它输出:
ans = 0
yes
ans = 1
yes
Run Code Online (Sandbox Code Playgroud)
有人知道为什么会这样,当x(1)为1时我怎么能输出'yes',否则输出'no'?
谢谢!