-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fail on weird values in VBA_orth * simplifies nan suite
- Loading branch information
1 parent
d7313d9
commit 85845bf
Showing
8 changed files
with
59 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,11 @@ | ||
function y = VBA_nanmean(x,dim) | ||
% FORMAT: Y = VBA_NANMEAN(X,DIM) | ||
% | ||
% Average or mean value ignoring NaNs | ||
function y = VBA_nanmean(varargin) | ||
% // VBA toolbox ////////////////////////////////////////////////////////// | ||
% | ||
% This function enhances the functionality of NANMEAN as distributed in | ||
% the MATLAB Statistics Toolbox and is meant as a replacement (hence the | ||
% identical name). | ||
% y = VBA_nanmean(varargin) | ||
% mean ignoring NaNs | ||
% | ||
% NANMEAN(X,DIM) calculates the mean along any dimension of the N-D | ||
% array X ignoring NaNs. If DIM is omitted NANMEAN averages along the | ||
% first non-singleton dimension of X. | ||
% see mean() for the arguments | ||
% | ||
% Similar replacements exist for NANSTD, NANMEDIAN, NANMIN, NANMAX, and | ||
% NANSUM which are all part of the NaN-suite. | ||
% | ||
% See also MEAN | ||
|
||
% ------------------------------------------------------------------------- | ||
% author: Jan Gl?scher | ||
% affiliation: Neuroimage Nord, University of Hamburg, Germany | ||
% email: [email protected] | ||
% | ||
% $Revision: 1.1 $ $Date: 2004/07/15 22:42:13 $ | ||
|
||
if isempty(x) | ||
y = NaN; | ||
return | ||
end | ||
|
||
if nargin < 2 | ||
dim = min(find(size(x)~=1)); | ||
if isempty(dim) | ||
dim = 1; | ||
end | ||
end | ||
|
||
% Replace NaNs with zeros. | ||
nans = isnan(x); | ||
x(isnan(x)) = 0; | ||
|
||
% denominator | ||
count = size(x,dim) - sum(nans,dim); | ||
|
||
% Protect against a all NaNs in one dimension | ||
i = find(count==0); | ||
count(i) = ones(size(i)); | ||
% ///////////////////////////////////////////////////////////////////////// | ||
|
||
y = sum(x,dim)./count; | ||
y(i) = i + NaN; | ||
y = mean(varargin{:},'omitnan'); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function [z, mu, sigma] = VBA_zscore (x, w, dim, nanflag) | ||
% // VBA toolbox ////////////////////////////////////////////////////////// | ||
% | ||
% [z, mu, sigma] = VBA_zscore (x, flag, dim, nanflag) | ||
% standard score, aka z-score | ||
% | ||
% Compute the stardardized zscore of x, ie z = (x - mean(x)) / std(x) | ||
% | ||
% ///////////////////////////////////////////////////////////////////////// | ||
|
||
if nargin < 2 || isempty (w) | ||
w = 0; | ||
end | ||
|
||
if nargin < 3 || isempty (dim) | ||
dim = find (size(x) > 1, 1); | ||
if isempty(dim) | ||
dim = 1; | ||
end | ||
end | ||
|
||
if nargin < 4 | ||
nanflag = 'includenan'; | ||
end | ||
|
||
mu = mean (x, dim, nanflag); | ||
sigma = std (x, w, dim, nanflag); | ||
sigma(sigma == 0) = 1; | ||
|
||
z = bsxfun(@minus, x, mu); | ||
z = bsxfun(@rdivide, z, sigma); |