如何打印某个位置的二进制字符串

时间:2013-09-05 10:11:36

标签: string matlab binary

考虑

a = dec2bin(rand(5,1)*100);
X = 3:7;
Z = 2:6;
for i = 1:5
    y    =  abs(X(i)-Z);
    dm   = min(y);
    D(i) = find(y==min(y));
end
D2 = D'
b  = a(D')

输出

a =
01001
01110
10000
10011
11111

X =
 3     4     5     6     7

Z =
 2     3     4     5     6

D2 =
 2
 3
 4
 5
 5

b =
0
1
1
1
1

为什么它没有返回

b = [01110
     10000
     10011
     11111]

我将如何获得此输出?

1 个答案:

答案 0 :(得分:2)

使用

b=dec2bin(a(D'))

这让我:

b =
110001
110000
110001
110000
110000