Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

How to assign indices to each row of a matrix according to a given codebook?

Asked by Parsa on 6 Oct 2013
Latest activity Answered by Walter Roberson 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.

0 Comments

Parsa

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson on 6 Oct 2013
index = codebook * [4; 2; 1] + 1;   %matrix multiply !

0 Comments

Walter Roberson

Contact us