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

📄 vswap.m

📁 JLAB is a set of Matlab functions I have written or co-written over the past fifteen years for the p
💻 M
字号:
function[varargout]=vswap(varargin)%VSWAP(X,A,B) replaces A with B in numeric array X%%   VSWAP(X,A,B) replaces A with B in numeric array X.  A and B may be%   numbers, NAN, +/- INF, or NAN+SQRT(-1)*NAN.%%   [Y1,Y2,...YN]=VSWAP(X1,X2,...XN,A,B) also works.%%   VSWAP(X1,X2,...XN,A,B); with no output arguments overwrites the %   original input variables.    %   __________________________________________________________________%   This is part of JLAB --- type 'help jlab' for more information%   (C) 2001, 2004 J.M. Lilly --- type 'help jlab_license' for details  if strcmp(varargin{1}, '--t')  vswap_test,returnend   a=varargin{end-1};b=varargin{end};for i=1:length(varargin)-2  x=varargin{i};  varargout{i}=swapnum1(x,a,b);endeval(to_overwrite(nargin-2))  function[x]=swapnum1(x,a,b)        if isfinite(a)  index=find(x==a);else  if isnan(a)    index=find(isnan(x));  elseif isinf(a)    if a>0        index=find(isinf(x)&x>0);    else        index=find(isinf(x)&x<0);    end  elseif isnan(real(a)) && isnan(imag(a))    index=find(isnan(real(x))&isnan(imag(x)));  endendif ~isempty(index)  x(index)=b;endfunction[]=vswap_testx=[1:10];ans1=[2 2:10];reporttest('VSWAP num case', aresame(vswap(x,1,2),ans1))x=[nan 1:10];ans1=[0:10];reporttest('VSWAP nan case', aresame(vswap(x,nan,0),ans1))

⌨️ 快捷键说明

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