📄 max.m
字号:
function [Smax,Imax] = max(S,varargin)if ~isnumeric(S) n = size(S); S = reshape(simplify(S(:)),n);endif issymbolic(S) error('MAX is not defined for symbolic variables');endn = size(S);switch nargin case 2% Smax = max(S,T) T = varargin{1}; if ~isnumeric(T) m = size(T); T = reshape(simplify(T(:)),m); end if issymbolic(T) error('MAX is not defined for symbolic variables'); end m = size(T); if (prod(m) == 1)% T is scalar DS = double(S(:)); DT = double(T); Smax = S(:); for i = 1:length(Smax) if (DS(i) < DT) Smax(i) = T; end Smax = reshape(Smax,n); end return elseif (prod(n) == 1) % S is scalar DS = double(S); DT = double(T(:)); Smax = T(:); for i = 1:length(Smax) if (DT(i) < DS) Smax(i) = S; end Smax = reshape(Smax,m); end return else% both are matrices if (length(m) ~= length(n)) error('dimensions must agree'); end if ~iszero(m-n) error('dimensions must agree'); end DS = double(S(:)); DT = double(T(:)); Smax = S(:); for i = 1:length(Smax) if (DS(i) < DT(i)) Smax(i) = T(i); end Smax = reshape(Smax,n); end return end case {1,3} if (nargin == 1) lnd = 1; % leading nonzero dimension for i = 2:length(n) if (n(lnd) == 1 & n(i) > 1) lnd = i; end end else lnd = varargin{2}; end D = reshape(double(S(:)),n); [Dmax,Imax] = max(D,[],lnd); nn = [n(1:lnd-1),1,n(lnd+1:end)]; Smax = sym(zeros(size(Dmax))); for i = 1:prod(nn) ind = index(nn,i); Smax(ind{:}) = S(ind{1:lnd-1},Imax(ind{:}),ind{lnd+1:end}); endend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -