Matlab instruction which give me index where the bits switch?
Show older comments
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
Tobias
on 14 Apr 2013
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.
Walter Roberson
on 14 Apr 2013
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)
Dario
on 14 Apr 2013
Answers (1)
Walter Roberson
on 14 Apr 2013
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
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!