source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/extras/@ncvar/median.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 1.9 KB
Line 
1function varargout=median(varargin)
2%MEDIAN (overloaded)
3%
4% M = median(x)
5%
6% MEDIAN is implemented using the overloaded SORT operator.
7
8% Author Johan Löfberg
9% $Id: median.m,v 1.1 2006/08/10 18:00:21 joloef Exp $
10
11x = varargin{1};
12
13if nargin > 1 | min(size(x))>1
14    error('SDPVAR/MEDIAN only supports simple 1-D median'),
15end
16
17switch length(x)
18    case 1
19        varargout{1} = x;
20    case 2
21        varargout{1} = sum(x);
22    otherwise
23        y = sort(x);
24        if even(length(x))
25            y1 = extsubsref(y,length(x)/2);
26            y2 = extsubsref(y,1+length(x)/2);
27            varargout{1} = (y1+y2)/2;
28        else
29            varargout{1} = extsubsref(y,ceil(length(x)/2));
30        end
31end
32
33
34%         
35%
36% switch class(x)
37%
38%     case 'double'
39%         y = sort(x)
40%         
41%                 if even(length(x))
42%                     y1 = y(length(x)/2);
43%                     y2 = y(1+length(x)/2);
44%                     varargout{1} = (y1+y2)/2;
45%                 else
46%                     varargout{1} = y(ceil(length(x)/2));
47%                 end
48%
49%     case 'sdpvar' % Overloaded operator for SDPVAR objects. Pass on args and save them.
50%
51%         if nargin > 1 | min(size(varargin{1}))>1
52%             error('SDPVAR/MEDIAN only supports simple 1-D median'),
53%         end
54%
55%         switch length(x)
56%             case 1
57%                 varargout{1} = x;
58%             case 2
59%                 varargout{1} = sum(x);
60%             otherwise
61%                 y = sort(x);
62%
63%                 if even(length(x))
64%                     y1 = y(length(x)/2);
65%                     y2 = y(1+length(x)/2);
66%                     varargout{1} = (y1+y2)/2;
67%                 else
68%                     varargout{1} = y(ceil(length(x)/2));
69%                 end
70%             otherwise
71%                 error('Strange type on first argument in SDPVAR/MEDIAN');
72%         end
Note: See TracBrowser for help on using the repository browser.