stugeling with if statement displaying results

1 回表示 (過去 30 日間)
Jacob
Jacob 2013 年 8 月 8 日
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

回答 (1 件)

kjetil87
kjetil87 2013 年 8 月 8 日
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 件のコメント
Jacob
Jacob 2013 年 8 月 8 日
great! thanks very much!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWord games についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by