Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: Incrementing Variables
Posted:
Oct 12, 2013 5:02 AM


"David Quilligan" <davidquilligan@hotmail.com> wrote in message <l39vcs$irq$1@newscl01ah.mathworks.com>... > Hi, I have an array of unit8 binary numbers. I need to concatenate every 2nd row i.e. the first with the second, the third with fourth etc. and then each of these back to a decimal and have them all in one array. I having trouble finding a way to do this without creating many many new variables. Length of array will vary but will be in the 1000?s. So far I have: > > % Convert XAccel to binary (uint8) and flip MSB > XAccelBin = de2bi(XAccel, 'leftmsb'); > > % Concatenate and change first row to a string > XAccelNewFirstRow = num2str([XAccelBin(2,:), XAccelBin(1,:)]); > > % Change first row back to decimal > XAccelNewFirstRow = bin2dec(XAccelNewFirstRow); > > % Concatenate and change second row to a string > XAccelNewSecondRow = num2str([XAccelBin(4,:), XAccelBin(3,:)]); > > % Change second row back to decimal > XAccelNewSecondRow = bin2dec(XAccelNewSecondRow); > > XAccelNewestFirstRow = [XAccelNewFirstRow; XAccelNewSecondRow]; > > Any help would be appreciated.
It's ok. Found a very simple and short solution. Just use:
XAccelNew = typecast(reshape(XAccel,1,[]),'uint16')';



