Matlab instruction which give me index where the bits switch?

Hi, if i've a matlab matrix of bits, for example C=[000,010,011], what is matlab instruction which give me the index of the matrix where there are commutations of bits (for example i have to know, in the third column, for which row index there is a switch from zero to one or viceversa).
Thanks

3 Comments

How about something like converting your matrix to a string and evaluating each element piece by piece? I don't have a final answer as to how you might get this to work when it comes to switching, but I figured my idea might get you thinking.
What is the exact representation of the matrix? When you write C=[000,010,011] do you mean that C is a vector of double in which the first element is 0, the second is decimal 10, the third is decimal 11? Or do you mean that C is a matrix of double [0,0,0; 0,1,0; 0,1,1] ? Or are they a different data type? If the value is 010 or 101 then do you need 2 indices returned or just the index of the first change? Or when you are asking for indices do you just need to know which of those clumps, 000, or 010, or 011, has such a transition? Is it important to know the indices or would a logical matrix of results do (because that would be constant size but indices might be different sizes)
My teacher has used a single insctruction (which i don't remember :( ) to make this. However my matrix comes from the sequent instruction : C=de2bi(double(Cg.x),10)'; where Ag is a matrix of elements belong to a Galois field.So C=[000,010,011] means that at first row, first column there is zero,at the second row, second column there is 1 etc...(all elements of matrix are bits). I want know, row by row, for which indices (columnes)there is a transition from zero to one or viceversa (for example if i've a row made by 0 0 0 1 1 1 0 0 1 the indices that i would are the fourth (beacuse is the first commutation), the seventh and the ninth).

Sign in to comment.

Answers (1)

diff(C) ~= 0
will be true in column K if column K was different than column K+1.
Because the number of indices could vary row by row, you cannot create a rectangular matrix of the indices, so you will need to apply find() row by row.

Categories

Asked:

on 14 Apr 2013

Community Treasure Hunt

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

Start Hunting!