Re: [問題] 關於&&的問題已回收

看板MATLAB作者 (神無月 孝臣)時間17年前 (2008/12/14 00:57), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《a89828290 (玉米)》之銘言: : 1 -1 : x=[-1 1] : 1 -1 : 0 : b=[0] : 0 : 我想用while迴圈設條件當 : b不等於x的"第一行"和不等於x的"第二行"就進去跑while迴圈 : 請問我要怎樣寫? : 我是這樣寫while b~=x(:,1) && b~=x(:,2) : 但是卻出現 : Operands to the || and && operators must be : convertible to logical scalar values. : 請問我要怎樣改才能成功呢? &&左右兩邊只能放純量的邏輯判斷 而你&&兩邊都是一個3x1的矩陣邏輯判斷 因為這是一個元素和一個元素去做判斷的 所以你只要把左右兩邊都變成純量的邏輯判斷就好了 使用any讓三個元素的~=判斷只要有一個1就成立 變成any(b~=x(:,1)) && any(b~=x(:,2))就好了 -- Deserves death! I daresay he does. Many that live deserve death. And some die that deserve life. Can you give that to them? Then be not too eager to deal out death in the name of justice, fearing for your own safty. Even the wise cannot see all ends. Gandalf to Frodo -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.225.206.62

12/14 01:44, , 1F
謝謝教導^.^
12/14 01:44, 1F
文章代碼(AID): #19G-bfEg (MATLAB)
討論串 (同標題文章)
文章代碼(AID): #19G-bfEg (MATLAB)