![](/img/trans.png)
[英]How to convert a logical vector of variable inputs into a function in matlab
[英]How to convert '1*1 char' to a logical vector in MATLAB?
实际上,我正在尝试将十六进制转换为bin。
a=hex2dec('ab32');
a=dec2bin(a);
%now I have a 1to1 char array of for example 1010101...
%I want to have an 1*16 array of 1 and 0's
我怎样才能做到这一点?
你可以这样做:
a=logical(a-'0')
例:
octave:224> a=hex2dec('ab32')
a = 43826
octave:225> a=dec2bin(a)
a = 1010101100110010
octave:226> a=logical(a-'0')
a =
1 0 1 0 1 0 1 1 0 0 1 1 0 0 1 0
octave:227> whos a
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
a 1x16 16 logical
Total is 16 elements using 16 bytes
octave:228>
这将为您提供1 * 16的实数向量,全为0或1:
(dec2bin(hex2dec('ab32'))-'0')
而这将为您提供1 * 16的逻辑向量,所有向量均为false或true(看起来像0和1)
(dec2bin(hex2dec('ab32'))-'0')==1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.