function [a,b] = maxn(varargin) ct = nargin; % 输入参数个数 if ct > 3, return; end; % 大于3个退出 A = varargin{1}; % 第一个为数组或矩阵 if ct == 2 N = varargin{2}; % 参数为两个则第二个为 n else N = 3; % 缺省 n = 3 end; [m,n] = size(A); if m == 1 a = max(A(1:N)); b = find(A(1:N)==a); else B = A(1:N,:); a = max(B); b = []; for k = 1:length(a) [h,l] = find(B(:,k)==a(k)); b = [b (k-1)*m+h]; % 转换为A的单下标 end; end;