[問題] 不取重複值已回收

看板MATLAB作者 (好時光)時間16年前 (2009/09/16 19:35), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
我想在4x4矩陣中,隨機取出8個數字 首先做index,之後再過濾掉重複的index 程式碼如下:(可是不是每次都會出現8組,請問要如何改進呢?) a=fix(rand(4,4)*10); row=fix((randperm(8)+1)/2); col=fix((randperm(8)+1)/2); index{1,1}(:,1)=row; index{1,1}(:,2)=col; i=1; while i<size(index{1,1},1) j=i+1; while j<size(index{1,1},1) if index{1,1}(i,:)==index{1,1}(j,:) index{1,1}(j,:)=[]; end j=j+1; end i=i+1; end -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 120.101.8.134
文章代碼(AID): #1AiCs50S (MATLAB)
文章代碼(AID): #1AiCs50S (MATLAB)