Commit bb3327c4 by Lee Carver

### Stealing some mean2 and std2 files from L. Farvacque

parent f9759391
 function [y,xok]=mean2(x,varargin) %MEAN2 Average or mean value. Ignores NaN and outliers. % For vectors, MEAN2(X) is the mean value of the elements in X. For % matrices, MEAN2(X) is a row vector containing the mean value of % each column. For N-D arrays, MEAN2(X) is the mean value of the % elements along the first non-singleton dimension of X. % % MEAN2(X,DIM) takes the mean along the dimension DIM of X. % % Example: If X = [0 1 2 % 3 4 5] % % then mean2(X,1) is [1.5 2.5 3.5] and mean2(X,2) is [1 % 4] % % MEAN2(X,DIM,LIMIT) Eliminates points with deviation larger than LIMIT*STD(X) % % [Y,OK]=MEAN2(X,...) returns a logical array OK indicating the accepted values % % See also MEDIAN, STD2, MIN2, MAX2, VAR, COV, MODE. [y,xs,xok]=statok2(x,1,varargin{:});
 function [xm,xs,xok]=statok2(x,varargin) dimx=size(x); if nargin < 3, dim=min(find(dimx ~= 1)); else dim=varargin{2}; end if nargin < 2, weight=1; else weight=varargin{1}; end if isempty(dim), dim = 1; end if dim == 1 if nargin < 4, thresh=NaN; else thresh=varargin{3}; end nc=prod(dimx(2:end)); xp=reshape(x,dimx(1),nc); xokp=isfinite(xp); [xpm,xps]=deal(NaN*ones(1,nc)); for j=1:nc xq=xp(:,j); ok=xokp(:,j); nok=sum(ok); go=nok>0; if nok while go xqm=sum(xq(ok),1)/nok; xqs=sqrt(var(xq(ok),weight,1)); xq0=xq; xq0(ok)=xqm; out=abs(xq-xq0)>(thresh*xqs); ok=ok & (~out); nok=sum(ok); go=(sum(out)>0) && (nok>0); end xpm(j)=xqm; xps(j)=xqs; xokp(:,j)=ok; else [xpm(j),xps(j)]=deal(NaN); xokp(:,j)=false; end end xm=reshape(xpm,[1 dimx(2:end)]); xs=reshape(xps,[1 dimx(2:end)]); xok=reshape(xokp,dimx); else perm=1:ndims(x); perm(dim)=[]; perm=[dim perm]; [xm1,xs1,xok1]= statok2(permute(x,perm),weight,1,varargin{3:end}); xm=ipermute(xm1,perm); xs=ipermute(xs1,perm); xok=ipermute(xok1,perm); end
 function [y,ok] = std2(varargin) %STD2 Standard deviation, ignoring NaN values. % For vectors, Y = STD2(X) returns the standard deviation. For matrices, % Y is a row vector containing the standard deviation of each column. For % N-D arrays, STD operates along the first non-singleton dimension of X. % % STD2 normalizes Y by N, where N is the sample size. It produces the square % root of the second moment of the sample about its mean. % STD2(X,1) is the same as STD(X). % % Y = STD2(X,0) normalizes by N-1. This is the sqrt of an unbiased estimator % of the variance of the population from which X is drawn, as long as X % consists of independent, identically distributed samples. % % Y = STD2(X,FLAG,DIM) takes the standard deviation along the dimension % DIM of X. Pass in FLAG==1 to use the default normalization by N, or % 0 to use N-1. % % Example: If X = [4 -2 1 % 9 5 7] % then std2(X,0,1) is [3.5355 4.9497 4.2426] and std2(X,0,2) is [3.0 % 2.0] % See also MEAN2. if nargin > 3 x=varargin{1}; w=varargin{2}; dim=varargin{3}; ok=isfinite(x); tile = ones(1,max(ndims(x),dim)); tile(dim) = size(x,dim); threshold=varargin{4}; while true y=sqrt(var2(x,w,dim)); overs=abs(x-repmat(mean2(x,dim),tile)) > repmat(threshold*y,tile); if ~any(overs(:)), break; end ok(overs)=false; x(overs)=NaN; end else y=sqrt(var2(varargin{:})); end
 ... ... @@ -4,4 +4,4 @@ ft.injoff = -6e-3; % set the injected - stored beam offset. TrajRM = ft.SimulateTrajectoryRM('RF',true,'rad',true); % simulate trajectory RM ModelRM = ft.ModelRM; % display computed trajectory RMs save('./@RingControl/SOLEIL_SimulatedRM.mat', 'ModelRM'); \ No newline at end of file save('/mntdirect/_machfs/carver/firstTurnsSoleil/first-turns-steering/@RingControl/SOLEIL_SimulatedRM.mat', 'ModelRM'); \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!