How to combine two matrix based on position and find the corresponding element?

I am having two matrix. one matrix element represent the position whereas other matrix contine the elements. Now i have to merge these two matrix based on position and to find corresponding element.
for example:
a=[ 5 6 3 7]
b=[011 101 010 001 100 110 111]
expected output:
c=[100 110 010 111]
i need to apply this problem to a larger n*m matrix.

 Accepted Answer

c = b(a)

3 Comments

Note: This works on your example, because a acts as a linear index into b. It unclear how to generalize what you need for a two-dimensional array.
Also, it is somewhat unclear what b represents. It seems that you are trying to encode something binary, but ...
b=[011 101 010 001 100 110 111]
b = 1×7
11 101 10 1 100 110 111
loses the leading zeros.
Thank you for your reply. But while applying this condition, only one bit from binary element is displayed as output.
otained output:
0
1
1
1
expected output:
010
100
110
111

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2020a

Asked:

on 26 Apr 2022

Commented:

on 28 Apr 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!