Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我有一个整数数组:
a=[3,4,5,6,7]; 我想将其转换为每个四位的二进制数组。对于上面的整数数组,我想获取以下二进制数组: abinary=[0,0,1,1, 0,1,0,0, 0,1,0,1, 0,1,1,0, 0,1,1,1]; 有什么快速的方法吗? 回答: Matlab具有内置功能DEC2BIN 。它创建了一个字符数组,但是很容易将其转换为数字。 %# create binary string - the 4 forces at least 4 bits bstr = dec2bin([3,4,5,6,7],4) %# convert back to numbers (reshape so that zeros are preserved) out = str2num(reshape(bstr',[],1))' 更多&回答... |
![]() |
![]() |