source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/@sdpvar/subsref.m @ 37

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

Added original make3d

File size: 4.2 KB
Line 
1function varargout = subsref(varargin)
2%SUBSREF (overloaded)
3
4% Author Johan Löfberg
5% $Id: subsref.m,v 1.17 2006/09/22 08:40:45 joloef Exp $
6
7% Stupid first slice call (supported by MATLAB)
8if  length(varargin{2}.subs) > 2
9    i = 3;
10    ok = 1;
11    while ok & (i <= length(varargin{2}.subs))
12        ok = ok & (isequal(varargin{2}.subs{i},1) | isequal(varargin{2}.subs{i},':'));
13        i = i + 1;
14    end
15    if ok
16        varargin{2}.subs = {varargin{2}.subs{1:2}};
17    else
18        error('??? Index exceeds matrix dimensions.');
19    end
20
21end
22
23if (isa(varargin{2}.subs{1},'sdpvar')) | (length(varargin{2}.subs)==2 & isa(varargin{2}.subs{2},'sdpvar'))
24    % *****************************************
25    % Experimental code for varaiable indicies
26    % *****************************************
27    varargout{1} = milpsubsref(varargin{:});
28    return
29else
30    X = varargin{1};
31    Y = varargin{2};
32end
33
34try
35    switch Y.type
36        case '()'
37            % Check for simple cases to speed things up (yes, ugly but we all want speed don't we!)
38            switch size(Y.subs,2)
39                case 1
40                    if isa(Y.subs{1},'sdpvar')
41                        varargout{1} = yalmip('addextendedvariable',mfilename,varargin{:});
42                        return
43                    else
44                        y = subsref1d(X,Y.subs{1});
45                    end
46                case 2
47                    y = subsref2d(X,Y.subs{1},Y.subs{2});
48                otherwise
49                    error('Indexation error.');
50            end
51        otherwise
52            error(['Indexation with ''' Y.type ''' not supported']) ;
53    end
54catch
55    error(lasterr)
56end
57if isempty(y.lmi_variables)
58    y = full(reshape(y.basis(:,1),y.dim(1),y.dim(2)));
59else
60    % Reset info about conic terms
61    y.conicinfo = [0 0];
62end
63varargout{1} = y;
64
65function X = subsref1d(X,ind1)
66
67% Get old and new size
68n = X.dim(1);
69m = X.dim(2);
70
71% Convert to linear indecicies
72if islogical(ind1)
73    ind1 = double(find(ind1));
74end
75
76% Ugly hack handle detect X(:)
77%pickall = 0;
78if ischar(ind1)
79    X.dim(1) = n*m;
80    X.dim(2) = 1;
81    return;
82end
83
84% Detect X(scalar)
85if length(ind1) == 1 & ind1 <= n*m
86   
87    Z = X.basis.';
88    Z = Z(:,ind1);
89    Z = Z.';
90    nnew = 1;
91    mnew = 1;
92   
93else
94
95    % What would the size be for a double
96    dummy = reshape(X.basis(:,1),n,m);
97    dummy = dummy(ind1);
98    nnew = size(dummy,1);
99    mnew = size(dummy,2);
100    [nx,mx] = size(X.basis);
101   
102    if length(ind1) > 1
103        Z = X.basis.';
104        Z = Z(:,ind1);
105        Z = Z.';
106    else
107        Z = X.basis(ind1,:);
108    end
109end
110
111% Find non-zero basematrices
112nzZ = find(any(Z(:,2:end),1));
113if ~isempty(nzZ)
114    X.dim(1) = nnew;
115    X.dim(2) = mnew;
116    X.lmi_variables =  X.lmi_variables(nzZ);
117    X.basis = Z(:,[1 1+nzZ]);
118else
119    bas = reshape(X.basis(:,1),n,m);
120    X.dim(1) = nnew;
121    X.dim(2) = mnew;
122    X.lmi_variables = [];
123    X.basis = reshape(bas(ind1),nnew*mnew,1);
124end
125
126function X = subsref2d(X,ind1,ind2)
127
128if ischar(ind1)
129    ind1 = 1:X.dim(1);
130end
131if ischar(ind2)
132    ind2 = 1:X.dim(2);
133end
134
135% Convert to linear indecicies
136if islogical(ind1)
137    ind1 = double(find(ind1));
138end
139
140% Convert to linear indecicies
141if islogical(ind2)
142    ind2 = double(find(ind2));
143end
144
145n = X.dim(1);
146m = X.dim(2);
147lind2 = length(ind2);
148lind1 = length(ind1);
149if lind2 == 1
150    ind1_ext = ind1(:);
151else
152    ind1_ext = kron(repmat(1,lind2,1),ind1(:));
153end
154if lind1 == 1
155    ind2_ext = ind2(:);
156else
157    ind2_ext = kron(ind2(:),repmat(1,lind1,1));
158end
159
160if prod(size(ind1_ext))==0 | prod(size(ind2_ext))==0
161    linear_index = [];
162else
163    % Speed-up for some bizarre code with loads of indexing of vector
164    if m==1 & ind2_ext==1
165        linear_index = ind1_ext;
166    else
167        linear_index = sub2ind([n m],ind1_ext,ind2_ext);
168    end
169end
170nnew = length(ind1);
171mnew = length(ind2);
172
173% Put all matrices in vectors and extract sub matrix
174Z = X.basis(linear_index,:);
175% Find non-zero basematrices
176nzZ = find(any(Z(:,2:end),1));
177if ~isempty(nzZ)
178    X.dim(1) = nnew;
179    X.dim(2) = mnew;
180    X.lmi_variables =  X.lmi_variables(nzZ);
181    X.basis = Z(:,[1 1+nzZ]);
182else
183    bas = reshape(X.basis(:,1),n,m);
184    X.dim(1) = nnew;
185    X.dim(2) = mnew;
186    X.lmi_variables = [];
187    X.basis = reshape(bas(linear_index),nnew*mnew,1);
188end
Note: See TracBrowser for help on using the repository browser.