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:
Even number/Odd number if statement

Subject: Even number/Odd number if statement

From: Stuart

Date: 6 Dec, 2010 10:49:05

Message: 1 of 19

Hi.

Currently im writing a code for fun that simulates a roulette wheel. i have coded it such that i can choose a number to bet on and it works fine. however it doesnt work when i tell it to bet odd or even.

The if statement im using contains these lines
if bet_number ==33
    if mod(Result+1,2)
       
       Cash = Cash + bet;
    else
        Cash = Cash - bet;
    end
end
if bet_number ==34
    if mod(Result,2)
      
       Cash = Cash + bet;
        else
        Cash = Cash - bet;
    end
end

bet_number ==33 denotes bet all odd numbers
bet_number ==34 denotes bet all even numbers

this combined with the rest of my script doesnt seem to work.

are there alternate functions i can uses as an if statement for if this is odd or if this is even, do this instead of mod

Subject: Even number/Odd number if statement

From: Steven_Lord

Date: 6 Dec, 2010 14:54:17

Message: 2 of 19



"Stuart " <imanotarat@gmail.com> wrote in message
news:idif31$qdd$1@fred.mathworks.com...
> Hi.
>
> Currently im writing a code for fun that simulates a roulette wheel. i
> have coded it such that i can choose a number to bet on and it works fine.
> however it doesnt work when i tell it to bet odd or even.

Define "doesnt [sic] work" -- does it throw a warning or error? Does it
give you a result you don't expect? Does it cause MATLAB to crash?

> The if statement im using contains these lines
> if bet_number ==33
> if mod(Result+1,2)
> Cash = Cash + bet;
> else Cash = Cash - bet;
> end

Show an example of the contents of the variables bet_number, Result, Cash,
and bet are when this code begins.

> end
> if bet_number ==34
> if mod(Result,2)
> Cash = Cash + bet;
> else Cash = Cash - bet;
> end
> end
>
> bet_number ==33 denotes bet all odd numbers

If Result is odd, then Result+1 is even and mod(Result+1, 2) is 0. In this
case you will subtract bet from Cash. Is that what you really want? I
think not.

> bet_number ==34 denotes bet all even numbers
>
> this combined with the rest of my script doesnt seem to work.
>
> are there alternate functions i can uses as an if statement for if this is
> odd or if this is even, do this instead of mod

You could write your own isodd or iseven functions if you wanted:

function tf = isodd(x)
tf = mod(x, 2) == 1;

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlab.wikia.com/wiki/FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Even number/Odd number if statement

From: Nicky

Date: 6 Dec, 2010 15:07:04

Message: 3 of 19

"Stuart " <imanotarat@gmail.com> wrote in message <idif31$qdd$1@fred.mathworks.com>...
> Hi.
>
> Currently im writing a code for fun that simulates a roulette wheel. i have coded it such that i can choose a number to bet on and it works fine. however it doesnt work when i tell it to bet odd or even.
>
> The if statement im using contains these lines
> if bet_number ==33
> if mod(Result+1,2)
>
> Cash = Cash + bet;
> else
> Cash = Cash - bet;
> end
> end
> if bet_number ==34
> if mod(Result,2)
>
> Cash = Cash + bet;
> else
> Cash = Cash - bet;
> end
> end
>
> bet_number ==33 denotes bet all odd numbers
> bet_number ==34 denotes bet all even numbers
>
> this combined with the rest of my script doesnt seem to work.
>
> are there alternate functions i can uses as an if statement for if this is odd or if this is even, do this instead of mod

You are using mod the wrong way. Currently for your odd bets, if mod(Result+1,2) returns 0 because the remainder is 0, it does not return true/false. So you either need to make your if statement say if ~mod(Result+1,2) or if mod(Result+1,2) == 0

Subject: Even number/Odd number if statement

From: Stuart

Date: 6 Dec, 2010 16:07:20

Message: 4 of 19

that seems to have fixed it


Thank you very much. i found the help topic on mod (much like most other new functions) not very useful and i didnt think i was applying it right

Subject: Even number/Odd number if statement

From: Steven_Lord

Date: 6 Dec, 2010 22:17:35

Message: 5 of 19



"Stuart " <imanotarat@gmail.com> wrote in message
news:idj1no$h6i$1@fred.mathworks.com...
> that seems to have fixed it
>
>
> Thank you very much. i found the help topic on mod (much like most other
> new functions) not very useful and i didnt think i was applying it right

In that case, please click on the No button in the lower-right corner of the
reference page in the Help Browser or the online documentation to indicate
that no, this was NOT helpful and explain why or what information you would
have liked that page to contain.

http://www.mathworks.com/help/techdoc/ref/mod.html

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlab.wikia.com/wiki/FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Even number/Odd number if statement

From: Matt Fig

Date: 6 Dec, 2010 22:39:05

Message: 6 of 19

"Stuart " <imanotarat@gmail.com> wrote in message <idj1no$h6i$1@fred.mathworks.com>...
> that seems to have fixed it
>
>
> Thank you very much. i found the help topic on mod (much like most other new functions) not very useful and i didnt think i was applying it right

MOD is a new function?

Subject: Even number/Odd number if statement

From: Walter Roberson

Date: 6 Dec, 2010 23:18:51

Message: 7 of 19

On 10-12-06 04:39 PM, Matt Fig wrote:
> "Stuart " <imanotarat@gmail.com> wrote in message
> <idj1no$h6i$1@fred.mathworks.com>...
>> that seems to have fixed it
>>
>>
>> Thank you very much. i found the help topic on mod (much like most
>> other new functions) not very useful and i didnt think i was applying
>> it right
>
> MOD is a new function?

Not at all. It even had its own TV series in the 1970's. Remember the catchy
theme music, "And then there's MOD" ?

Subject: Even number/Odd number if statement

From: Matt Fig

Date: 7 Dec, 2010 00:06:05

Message: 8 of 19

Theme songs for MATLAB functions, what a great idea! Imagine if the song you referenced started playing when "help mod" was typed at the command prompt! That would make for some interesting workplace conversations.

Subject: Even number/Odd number if statement

From: Walter Roberson

Date: 7 Dec, 2010 01:01:22

Message: 9 of 19

On 10-12-06 06:06 PM, Matt Fig wrote:
> Theme songs for MATLAB functions, what a great idea! Imagine if the
> song you referenced started playing when "help mod" was typed at the
> command prompt!

"A white sports COT..."

"SIGN, SIGN, everywhere a SIGN..."

"Be COS of you, there's a song in my heart..."

"Taya-TAN, taya-TAN, taya-TAN
Watashi no tokimekiyo..."
( http://www.youtube.com/watch?v=EjhjdA0yeAY&feature=related )

"Imagine there's no HEAVISIDE,
it's easy if you try..."

"Operator, can you help me TRACE this call? ..."

Subject: Even number/Odd number if statement

From: Steven_Lord

Date: 7 Dec, 2010 15:51:09

Message: 10 of 19



"Matt Fig" <spamanon@yahoo.com> wrote in message
news:idjtpd$9ht$1@fred.mathworks.com...
> Theme songs for MATLAB functions, what a great idea! Imagine if the song
> you referenced started playing when "help mod" was typed at the command
> prompt! That would make for some interesting workplace conversations.

Whenever you call INV, the theme from Jaws starts playing?

If only there was a song scary enough for a call to EVAL. Maybe the theme
from Psycho? ;)

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlab.wikia.com/wiki/FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Even number/Odd number if statement

From: Sean de

Date: 7 Dec, 2010 16:26:06

Message: 11 of 19

Walter Roberson <roberson@hushmail.com> wrote in message
> "Imagine there's no HEAVISIDE,
> it's easy if you try..."

IF you TRY

Subject: Even number/Odd number if statement

From: Jan Simon

Date: 7 Dec, 2010 17:04:21

Message: 12 of 19

Dear Steven,

> If only there was a song scary enough for a call to EVAL. Maybe the theme
> from Psycho? ;)

Pink Floyed: Another brick in th' eval.

Or of course:
Wise Guys - Die Heldensage vom heiligen Evald (FC Köln Song):
  http://www.youtube.com/watch?v=Yn-kBjLsPUA

However, I'm searching for a song matching the most ugliest function name ever: ISEQUALWITHEQUALNANS.

Kind regards, Jan

Subject: Even number/Odd number if statement

From: Matt Fig

Date: 7 Dec, 2010 17:17:20

Message: 13 of 19

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message
> However, I'm searching for a song matching the most ugliest function name ever: ISEQUALWITHEQUALNANS.
>
> Kind regards, Jan

Ugliest, that is, until TMW comes out with the function to cut NG traffic by 20%:

ISEQUALWITHBLISSFULIGNORANCEOFFLOATINGPOINTCONSIDERATIONS

This function would return true when one comparand is equal in a "come on, of course it 'should' be equal" way to the other.

Subject: Even number/Odd number if statement

From: Walter Roberson

Date: 7 Dec, 2010 19:28:36

Message: 14 of 19

On 10-12-07 11:04 AM, Jan Simon wrote:
> Dear Steven,
>
>> If only there was a song scary enough for a call to EVAL. Maybe the
>> theme from Psycho? ;)
>
> Pink Floyed: Another brick in th' eval.

Hmmm, I found something that is partly relevant:

http://www.burbler.com/queso-furlan-lyrics.html

Evaluate your soul with different kind of being
Lust that comes within
Instinctively, banish it with purity
Purity and growth
Evaluate your soul with different kind of being
Instinctively, banish it with purity


Also, buried in the comments of the lyrics of song by a band appropriately
named "Cradle Of Filth", one of the reviewers referred to "the principal of
eval made flesh". I believe they meant 'principle' but contextually it is
difficult to be sure. (No link because the lyrics themselves are not suitable
for most workplaces.)

Subject: Even number/Odd number if statement

From: Bruno Luong

Date: 7 Dec, 2010 20:33:05

Message: 15 of 19

It's a stupid candidate for Matlab song, but nowhere comparable to Jan's Pink Floyd "another brick of eval" (Love it)

http://www.youtube.com/watch?v=Qu5H13gvu-g

Bruno

Subject: Even number/Odd number if statement

From: Walter Roberson

Date: 7 Dec, 2010 20:56:15

Message: 16 of 19

On 10-12-07 02:33 PM, Bruno Luong wrote:
> It's a stupid candidate for Matlab song, but nowhere comparable to Jan's
> Pink Floyd "another brick of eval" (Love it)
>
> http://www.youtube.com/watch?v=Qu5H13gvu-g

"Tic Toc" ? Hmmm -- for those, I tend to think of
"Repent, Harlequin!" Said the Ticktockman
except that isn't a song.

So the next thing I would think of would be the clock scene from Metropolis. I
would, though, need to re-watch to check whether in the Moroder version, that
matched "Cage of Freedom" or "Blood From A Stone".

Subject: Even number/Odd number if statement

From: Jan Simon

Date: 7 Dec, 2010 21:18:06

Message: 17 of 19

Dear Matt,

> Ugliest, that is, until TMW comes out with the function to cut NG traffic by 20%:
> ISEQUALWITHBLISSFULIGNORANCEOFFLOATINGPOINTCONSIDERATIONS

1. TMW will not be enthusiastic if the NG has 20% less participation.
2. The command has 57 characters - no chance for the important backport to Matlab 5.3.

I'd suggest a more flexible approach to replace ISMEMBER by:
  WantedResult = SHOULDBEMEMBER(x, y, WantedResult)
Of course "I've got the power" (Snap) will be played, when calling this command the first time.

Jan

Subject: Even number/Odd number if statement

From: Sean de

Date: 7 Dec, 2010 21:27:07

Message: 18 of 19

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <idm8ae$m7d$1@fred.mathworks.com>...
> Dear Matt,
>
> > Ugliest, that is, until TMW comes out with the function to cut NG traffic by 20%:
> > ISEQUALWITHBLISSFULIGNORANCEOFFLOATINGPOINTCONSIDERATIONS
>
> 1. TMW will not be enthusiastic if the NG has 20% less participation.
> 2. The command has 57 characters - no chance for the important backport to Matlab 5.3.
>
> I'd suggest a more flexible approach to replace ISMEMBER by:
> WantedResult = SHOULDBEMEMBER(x, y, WantedResult)
> Of course "I've got the power" (Snap) will be played, when calling this command the first time.
>
> Jan

SHOULDBEMEMBER would have no reason to call POWER; unless of course it felt like it @MOMENT

Subject: Even number/Odd number if statement

From: Walter Roberson

Date: 8 Dec, 2010 20:24:04

Message: 19 of 19

On 10-12-07 09:51 AM, Steven_Lord wrote:
>
>
> "Matt Fig" <spamanon@yahoo.com> wrote in message
> news:idjtpd$9ht$1@fred.mathworks.com...
>> Theme songs for MATLAB functions, what a great idea! Imagine if the
>> song you referenced started playing when "help mod" was typed at the
>> command prompt! That would make for some interesting workplace
>> conversations.
>
> Whenever you call INV, the theme from Jaws starts playing?
>
> If only there was a song scary enough for a call to EVAL. Maybe the
> theme from Psycho? ;)

Alice Cooper, "Welcome to My Nightmare" ?

Some of the non-linear works of John Cage?

Tags for 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