b = [1,2,10,4,5;6,7,8,9,10;11,8,13,14,15;16,17,20,19,20];
% 求出两两相减的列索引
ic = perms(1:5);
ic = ic(:,1:2);
ic = sort(ic,2);
ic = unique(ic,'rows');
w = length(ic);
[m,n] = size(b);
% 求出所有列两两相减的绝对值
absv = zeros(m,w);
for p = 1:w
p1 = b(:,ic(p,1));
p2 = b(:,ic(p,2));
absv(:,p) = abs(p1-p2);
end
% 求最大值
maxv = zeros(m,3);
maxv(:,1) = max(absv')';
% 求最小值
minv = zeros(m,3);
minv(:,1) = min(absv')';
% 找出所有得到大小值的列索引
for p = 1:m
id = find(maxv(p,1)==absv(p,:));
if length(id)>1, id = id(1); end;
maxv(p,2:3) = ic(id,:);
id = find(minv(p,1)==absv(p,:));
if length(id)>1, id = id(1); end;
minv(p,2:3) = ic(id,:);
end
maxv
minv
maxv =
9 1 3
4 1 5
7 2 5
4 1 3
minv =
1 1 2
1 1 2
1 3 4
0 3 5