0

consider

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')

Output is

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

why it did not return

b = [01110
     10000
     10011
     11111]

How will i get this output?

1 Answer 1

2

Use

b=dec2bin(a(D'))

That gives me:

b =
110001
110000
110001
110000
110000
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.