Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
c++ to matlab port_question

Subject: c++ to matlab port_question

From: Aidy

Date: 14 Feb, 2011 05:59:05

Message: 1 of 3

Hello everyone,

I am trying to port an algorithm from C++ to matlab.

In C++ I have encountered the following piece of code with a condition as follows :

!(A & B)

where A and B are matices.

My interpretation of this condition is :

Condition interpretation of C++ code : when both A and B not equal to each other .

If anyone is familiar with this let me know if I'm interpreting this code correctly.

cheers,
aidy

Subject: c++ to matlab port_question

From: Aidy

Date: 14 Feb, 2011 06:46:04

Message: 2 of 3

Hello again,

In relation to my first post. The particular block of C++ code I am have an issue with is :


//////////////////////////////////////////////////////////////////////////////////////
  int code_P[2], // codes de P[n]
 i, bit_i, // i -> (0000100...)
 n;

if(code_P[0] != 0000)
   {
n=0; // c'est P[0] qu'on clippera
      for(i=0,bit_i=1; !(code_P[0] & bit_i); i++,bit_i<<=1)// !(code_P[0] & bit_i) means if each bit in "code_P[0]" and in each bit in "bit_i" is NOT EQUAL
{;}

   }


   else
{
n=1; // c'est P[1] qu'on clippera
      for(i=0,bit_i=1; !(code_P[1] & bit_i); i++,bit_i<<=1) // !(code_P[1] & bit_i) means if each bit in "code_P[1]" and in each bit in "bit_i" is NOT EQUAL
{;}

   }
/////////////////////////////////////////////////////////////////////////////////////////////

I am not sure how to interpret the statements in the 2 for loops , so that I can understand them to convert into Matlab code.

Anyone with some understanding of C++ and Matlab , please lend some advice.

--aidy

Subject: c++ to matlab port_question

From: P-GPS

Date: 14 Feb, 2011 07:07:37

Message: 3 of 3

That condition is using bitwise operators. There is a 'bitand'
function in Matlab. Try checking out its help.


On Feb 14, 1:46 am, "Aidy " <aidenj...@gmail.com> wrote:
> Hello again,
>
> In relation to my first post. The particular block of C++ code I am have an issue with is :
>
> ///////////////////////////////////////////////////////////////////////////­///////////
>   int code_P[2], // codes de P[n]
>  i, bit_i,                // i -> (0000100...)
>  n;
>
> if(code_P[0] != 0000)
>    {
>                         n=0;   // c'est P[0] qu'on clippera
>       for(i=0,bit_i=1;  !(code_P[0] & bit_i);  i++,bit_i<<=1)// !(code_P[0] & bit_i) means if each bit in "code_P[0]" and in each bit in "bit_i" is NOT EQUAL
>           {;}
>
>    }
>
>    else
>          {
>                         n=1;   // c'est P[1] qu'on clippera
>       for(i=0,bit_i=1;  !(code_P[1] & bit_i);  i++,bit_i<<=1) // !(code_P[1] & bit_i) means if each bit in "code_P[1]" and in each bit in "bit_i" is NOT EQUAL
>           {;}
>
>    }
> ///////////////////////////////////////////////////////////////////////////­//////////////////
>
> I am not sure how to interpret the statements in the 2 for loops , so that I can understand them to convert into Matlab code.
>
> Anyone with some understanding of C++ and Matlab , please lend some advice.
>
> --aidy

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us