Skip to content

Commit

Permalink
add range utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Aug 26, 2023
1 parent e9640eb commit 156fce0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/utils/range.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function y = range(x,dim)
%RANGE Sample range.
% Y = RANGE(X) returns the range of the values in X. For a vector input,
% Y is the difference between the maximum and minimum values. For a
% matrix input, Y is a vector containing the range for each column. For
% N-D arrays, RANGE operates along the first non-singleton dimension.
%
% RANGE treats NaNs as missing values, and ignores them.
%
% Y = RANGE(X,DIM) operates along the dimension DIM.
%
% See also BOUNDS, MIN, MAX, IQR, MAD, STD.

% Copyright 1993-2016 The MathWorks, Inc.


if nargin < 2
y = max(x) - min(x);
else
y = max(x,[],dim) - min(x,[],dim);
end

0 comments on commit 156fce0

Please sign in to comment.