[maxval,maxind]=maxmd(x) Find the largest element of a multi dimensional array and it's indexes, working over all dimensions, not just the first singleton as does normal min(A) function. Warning - will not currently work if more than one identical max values
0001 function [C,I]=maxmd(A) 0002 % [maxval,maxind]=maxmd(x) 0003 % 0004 % Find the largest element of a multi dimensional array 0005 % and it's indexes, working over all dimensions, not just 0006 % the first singleton as does normal min(A) function. 0007 % 0008 % Warning - will not currently work if more than one 0009 % identical max values 0010 0011 [C,I]=max(A(:)); 0012 0013 str='['; 0014 for i=1:ndims(A) 0015 str=strcat(str,sprintf('I(%d),',i)); 0016 end 0017 str=str(1:end-1); 0018 eval([str,']=ind2sub(size(A),I);']); 0019 0020 return