1

I have arrays that stores only binary numbers like the below, binaries are of the size 1x31. Now I want to make the last bit the first and the first bit the last and so on. The choice of data structure is probably very poor here -- when I learn to play with binaries I probably get rid of the array. The binaries make the ordering of the arrays far easier with a simple sort. Anyway this is puzzle now:

Is there some ready command in Matlab for changing desceding binary to asceding binary?

Input

>> C(21,:)

ans =

   (1,11)       1
   (1,16)       1
   (1,17)       1


>> full(C(21,:))

ans =

  Columns 1 through 11

     0     0     0     0     0     0     0     0     0     0     1

  Columns 12 through 22

     0     0     0     0     1     1     0     0     0     0     0

  Columns 23 through 31

     0     0     0     0     0     0     0     0     0

Goal for the output with some command such as invertDec2Asc

>> invertDec2Asc(C(21,:))

ans =

   (1,21)       1
   (1,16)       1
   (1,15)       1
4

2 回答 2

2

尝试使用num2str后跟fliplr

revnum = fliplr( num2str(num) )

测试

num = ['101010';'010101']
revnum = fliplr( num2str(num) )

num =

101010
010101

revnum =

010101
101010
于 2013-10-26T13:24:27.730 回答
1

flipud或者fliplr是你正在寻找的。

Matlab 文档

fliplr([1 0 1 0]) = [0 1 0 1]
fliplr('1010') = '0101' 

matlab 中的二进制格式:'1010',例如用dec2bin(10)

于 2013-10-26T12:58:44.773 回答