⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maxloc.m

📁 Replicates the functionality of maxloc in fortran
💻 M
字号:
From: <由 Microsoft Internet Explorer 5 保存>
Subject: 
Date: Thu, 27 Mar 2008 20:16:34 +0800
MIME-Version: 1.0
Content-Type: text/html;
	charset="gb2312"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://www.mathworks.com/matlabcentral/files/19331/maxloc.m
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dgb2312">
<META content=3D"MSHTML 6.00.2900.3268" name=3DGENERATOR></HEAD>
<BODY><PRE>function out=3Dmaxloc(x,dim)
%function out=3Dmaxloc(x,dim)
%
%  Replicates the functionality of maxloc in fortran.
%
%  INPUTS:       x -&gt; data variable   =20
%              dim -&gt; (optional) dimension upon which to operate
%                     (same in Fortran and Matlab)
%
% OUTPUTS:     out -&gt; set to second output of Matlab's max() if dim =
is specified
%                     otherwise, is the maximum location for the entire =
array
%                     returned as a cell array resulting from ind2sub
%                     this could then be used as a subscript list
%
% EXAMPLES:   a=3Dmagic(5); b=3Dmaxloc(a); a(b{:}),b
%                         b=3Dmaxloc(a,1)
%
% author: Ben Barrowes 3/2008, barrowes@alum.mit.edu


if nargin&lt;2, dim=3D0; end

xdim=3Dlength(size(x));
if dim=3D=3D0
 [dumvar,tempOut]=3Dmax(x(:));
 out=3Dcell(1,xdim);
 [out{:}]=3Dind2sub(size(x),tempOut);
 %out=3D[out{:}];
else
 if ~isnumeric(dim), error('dim must be anumber in maxloc'); end
 if dim~=3Dround(dim), error('dim must be an integer in maxloc'); end
 if dim&gt;xdim || dim&lt;1, error('dim must be =
0&lt;dim&lt;=3Dlength(size(x))'); end
 [dumvar,out]=3Dmax(x,[],dim);
end

</PRE></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -