Re: [問題] 邏輯判斷問題已回收

看板MATLAB作者 (Steven)時間16年前 (2009/10/17 10:16), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《sylviachines (菇)》之銘言: : 題目要我算出一個1*3的矩陣 : 每個值都是隨機的 且介於0~9 : 當矩陣中出現兩個以上7的時候 : 跑出"lucky"的字串 : 否則就是unlucky : 簡單來說就是類似那種會出現3個7的拉霸 : 這是我寫的程式 : x =fix(rand(1,3)*9) index = find( x == 7 ); if ( ~isempty(index) ) if ( length(index) >= 2 ) disp('Lucky'); else disp('unlucky'); end else disp('Unlucky'); end : if find(x==7) ans=[1&&3]; : disp('Lucky'); : elseif find(x==7) ans=[2&&3]; : disp('Lucky'); : elseif find(x==7) ans=[1&&2]; : disp('Lucky'); : elseif find(x==7) ans=[1&&2&&3]; : disp('Lucky'); : else : disp('Unlucky'); : end -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.167.57.202
文章代碼(AID): #1AsIZfpj (MATLAB)
文章代碼(AID): #1AsIZfpj (MATLAB)