Asked by Parsa
on 6 Oct 2013

Suppose that we have a 10^6 by 3 matrix **A** with binary ( 0 or 1) elements. On the other hand, we have a codebook like

codebook =[0,1,1 ; 0,0,1 ; 0,1,0 ; 0,0,0 ; 1,0,0 ; 1,1,0 ; 1,0,1 ; 1,1,1];

I'm looking for a fast code to generate a 10^6 by 1 matrix ( **Index** ) which shows the corresponding row number for each row according to the **codebook** . For example if the second row of the **A** is [1 0 0], the second element of the **Index** must be 5.

Thanks for your help.

*No products are associated with this question.*

Answer by Walter Roberson
on 6 Oct 2013

index = codebook * [4; 2; 1] + 1; %matrix multiply !

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments