File: psychrange.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (34 lines) | stat: -rw-r--r-- 1,135 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function r = psychrange(varargin)
% r = psychrange(X [, dims]) - Drop in replacement for range().
%
% See Matlab online docs, or Octave help for range().
%
% Matlab does not have range() outside the statistics toolbox, and we do
% not want to enforce installation of it for the few use-cases we have
% internally for range(), so provide this drop-in / fallback inplementation.
%
% Octave would not benefit from this, as range is part of statistics package,
% but so are min and max, so if range isn't there, the min and max functions
% needed here won't be either.
%

% History
% 01-Feb-2021   mk  Written.

    % range() exists?
    if ismember(exist('range'), [2,3])
        % Use it:
        r = range(varargin{:});
    else
        % Implement trivial fallback implementation:
        if nargin < 1 || nargin > 2
            error('Invalid number of arguments to fallback psychrange() provided. Must be one or two.');
        end

        if nargin == 1
            r = max(varargin{1}) - min(varargin{1});
        else
            r = max(varargin{1}, [], varargin{2}) - min(varargin{1}, [], varargin{2});
        end
    end
end