ismemb.m
来自「JLAB is a set of Matlab functions I have」· M 代码 · 共 41 行
M
41 行
function[bool]=ismemb(a,b,tol)% ISMEMB Tests whether the elements of an array are members of a set.%% ISMEMB(A,B) for scalar A is true if A is a member of the array B,% and false otherwise. For array A, ISMEMB tests whether each% element of A is a member of B, and returns an array of size% SIZE(A).%% Equality is judged to within a small numerical tolerance specified% by ISMEMB(A,B,TOL), with a default of TOL=1e-10;%% See also SUBSET, LOOKUP% _________________________________________________________________% This is part of JLAB --- type 'help jlab' for more information % (C) 2003, 2004 J.M. Lilly --- type 'help jlab_license' for details if nargin==2 tol=1e-10; endif any(~isfinite(a)) || any(~isfinite(b)) error('Elements of A and B should be finite (non-NAN, non-INF).')endbool=ones(size(a));a=a(:);b=b(:);%bool1=(osum(a,-b)==0);bool1=(abs(osum(a,-b))<=tol);index=find(sum(bool1,2)==0); %this is equivalent to "any"bool(index)=0;%This convienently gets around explicitly needing to know the %dimensionality of A, and also reshaping.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?