2013-10-22 63 views

回答

0
a = [ 4 2 5 9] 

    a = 

     4  2  5  9 

    s = combnk(a, 2) 

    s = 

     5  9 
     2  9 
     2  5 
     4  9 
     4  5 
     4  2 
+0

请添加一点说明文字。 – IvanH

+1

函数在这里解释:http://www.mathworks.de/de/help/stats/combnk.html – Daniel

+0

谢谢,丹尼尔。 –

4

你并不需要一个for循环:

result = tril(bsxfun(@minus,a(:).',a(:)),-1); 
ind = tril(reshape(1:numel(result),size(result)),-1); 
ind = ind(ind>0); 
result = result(ind).' 
+6

我喜欢这个,因为它回答了这个问题,并在同一OP不能使用它(大概是为了介绍MATLAB类)! –

+0

好的解决方案Luis。我打算发布的解决方案是一个循环的双。他要求它:) – MZimmerman6

+0

@DangKhoa呃...我没有想到这一点! :-) –