http://i.imgur.com/B5WVDs9.jpg
如圖
有哪幾行程式碼比較不重要或是可以縮減
讓程式碼最佳化
clear all
close all
T=[randperm(13); randperm(13); randperm(13); randperm(13)];
ABCD=[T(1:5);T(6:10);T(11:15);T(16:20)]
for i=1:4,
for j=1:5,
ind=find(ABCD(i,:)==ABCD(i,j));
if length(ind)>1,
ABCD(i,j,ind)=0;
end
end
end
A=ABCD(1,find(ABCD(1,:)~=0))
B=ABCD(2,find(ABCD(2,:)~=0))
C=ABCD(3,find(ABCD(3,:)~=0))
D=ABCD(4,find(ABCD(4,:)~=0))
[temp,I]=sort([length(A) length(B) length(C) length(D)]);
N=['A','B','C','D'];
fprintf('The winner order is: %s.\n',N(I))