Beginner needs help with following syntax:

View: New views
5 Messages — Rating Filter:   Alert me  

Beginner needs help with following syntax:

by balteo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
I have the following matlab code that I am trying to run under octave:

1. function B=Binaire(p)
2. U= rand;
3. B=(U<=p);
4. end


Can anyone please translate line 3. into plain English?
Thanks in advance,
Julien.

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: Beginner needs help with following syntax:

by Søren Hauberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

lør, 07 11 2009 kl. 08:28 +0100, skrev Julien Martin:
> 3. B=(U<=p);

This is the same as writing

  if (U <= p)
    B = 1;
  else
    B = 0;
  endif

Søren

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: Beginner needs help with following syntax:

by balteo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Soren!

2009/11/7 Søren Hauberg <soren@...>
lør, 07 11 2009 kl. 08:28 +0100, skrev Julien Martin:
> 3. B=(U<=p);

This is the same as writing

 if (U <= p)
   B = 1;
 else
   B = 0;
 endif

Søren



_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: Beginner needs help with following syntax:

by Francesco Potortì :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>> 3. B=(U<=p);
>
>This is the same as writing
>
>  if (U <= p)
>    B = 1;
>  else
>    B = 0;
>  endif

Almost.  In the first case, one gets:

octave> typeinfo(B)
ans = bool

while in the second case one gets:

octave> typeinfo(B)
ans = scalar

To be just the same, your example should be:

if (U <= p)
  B = true;
else
  B = false;
endif

--
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: Potorti@...
(entrance 20, 1st floor, room C71)     Web:   http://fly.isti.cnr.it/
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: Beginner needs help with following syntax:

by bharat pathak :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hello julien
 
    p is the threshold parameter that is passed as an
    input to the function. let us assmue it's value is 0.5
 
    p = 0.5
 
    now every time you call the function from main environment
    or m-file, a random number in the range of [0 to 1] is generated
    in line 2, and this value is assigned to variable U
 
    on line 3 the generated random number is compared with threshold.
    in this example we assume p = 0.5. hence if the generated random
    number U happens to be less than or equal to threshold p, then
    value of B is 1, else the value of B is 0.
 
    hence this code helps in generation of binary random number
    based on the provided threshold.
 
regards
bharat

From: balteo@...
Sent: Saturday, November 07, 2009 12:58 PM
Subject: Beginner needs help with following syntax:

Hello,
I have the following matlab code that I am trying to run under octave:

1. function B=Binaire(p)
2. U= rand;
3. B=(U<=p);
4. end


Can anyone please translate line 3. into plain English?
Thanks in advance,
Julien.


_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave