isconstant.m

来自「实现地震勘探中」· M 代码 · 共 37 行

M
37
字号
function bool=isconstant(a,epsilon)% Function checks if all elements of array "a" are the same within% limits median(a)*(1 +/- epsilon) (relative error) or,% if median(a) < eps, within limits +/- epsilon (absolute error).%% Written by: E. R.: November 14, 2005% Last updated: April 16, 2008: rewritten to work with matrices%%          bool=isconstant(a,epsilon)% INPUT% a        numeric vector or matrix; if "a" is a matrix, the check is performed% columnwise% epsilon  maximum relative deviation %          Default: epsilon = 0% OUTPUT% bool     logical variable%          true if all entries of "a" are the same within the limits,%          false  otherwise%% EXAMPLE%          bool1=isconstant([1 1 1 1.2],0.5)%          bool2=isconstant(rand(5,7),0.2)[a,nshifts]=shiftdim(a);if nargin == 1  ||  epsilon == 0   bool=all(bsxfun(@eq,a,a(1,:)));else   ma=median(a);   meps=abs(ma*epsilon);   meps(abs(ma)<eps)=abs(epsilon);   bool=all((bsxfun(@le,a,a(1,:)+meps))  &  (bsxfun(@ge,a,a(1,:)-meps))); endbool=shiftdim(bool,-nshifts);

⌨️ 快捷键说明

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