Effacer les filtres
Effacer les filtres

stugeling with if statement displaying results

2 vues (au cours des 30 derniers jours)
Jacob
Jacob le 8 Août 2013
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

Réponses (1)

kjetil87
kjetil87 le 8 Août 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.
  1 commentaire
Jacob
Jacob le 8 Août 2013
great! thanks very much!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Just for fun dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by