The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Incrementing Variables
Replies: 1   Last Post: Oct 12, 2013 5:02 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
David Quilligan

Posts: 10
Registered: 10/11/13
Re: Incrementing Variables
Posted: Oct 12, 2013 5:02 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"David Quilligan" <> wrote in message <l39vcs$irq$>...
> 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, 'left-msb');
> % 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')';

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.