Clear Filters
Clear Filters

stugeling with if statement displaying results

2 views (last 30 days)
I am trying to write a file to simulate a roulette game, I am up to the if statement and trying to get matlab to display either green,red,or black for a random spin of the roulette table. it will display green as i used an if statement for that but it wont display red or black...i think it has something to do with the way i entered the numbers... this is how i have set out the file....
%% Roulette simulation clear, clc x = randi([0,36]) if x==0 disp('green') elseif x==[1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36] disp('red') elseif x==[2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35] disp('black') end

Answers (1)

kjetil87
kjetil87 on 8 Aug 2013
You are correct. It is how you compare x. The result will be a vector containing lots of false and maybe one true. If you change it to ;
elseif any(x==[1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36])
It will work.

Categories

Find more on Just for fun in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!