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

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

Added original make3d

File size: 2.1 KB
Line 
1function y = stackcell(dummy,blocks)
2%STACKCELL Internal function for rapid concatenation
3%
4% [x1 x2 ... xn] is written as stackcell(sdpvar(1,1),{x1,x2,x3,...,xn})
5% Why the first argument? A hack to make it a method for sdpvar...
6
7
8% Author Johan Löfberg
9% $Id: stackcell.m,v 1.1 2006/08/10 18:00:22 joloef Exp $
10
11nblocks = size(blocks,2);
12% Get dimensions
13n = zeros(nblocks,1);
14m = zeros(nblocks,1);
15isasdpvar = zeros(nblocks,1);
16% Get dimensions
17for i = 1:nblocks
18    [n(i),m(i)]=size(blocks{i});
19    isasdpvar(i) = isa(blocks{i},'sdpvar');
20end
21
22if ~any(isasdpvar)
23    y = blocks{1};
24    for i = 2:length(blocks)
25        y = [y blocks{i}];
26    end
27    return;
28end
29
30% Keep only non-empty
31keep_these = find((n.*m)~=0);
32if length(keep_these)<length(n)
33    blocks = {blocks{keep_these}};
34    n = n(keep_these);
35    m = m(keep_these);
36    isasdpvar=isasdpvar(keep_these);
37    nblocks = length(n);
38end;
39
40% Find all free variables used
41all_lmi_variables = [];
42for i = 1:nblocks
43    if isasdpvar(i)
44        all_lmi_variables = [all_lmi_variables blocks{i}.lmi_variables];
45    end
46end
47all_lmi_variables = uniquestripped(all_lmi_variables);
48
49% Pick one of the sdpvar objects to build on...
50y = blocks{min(find(isasdpvar))};
51
52% Some indexation tricks
53n = n(1);
54allindextopos = (sparse(1,[1;1+all_lmi_variables(:)],1:1+length(all_lmi_variables),1,1+all_lmi_variables(end)));
55
56basis = [];
57basis_i = [];
58basis_j = [];
59basis_s = [];
60shft = 0;
61for j = 1:nblocks
62    if isasdpvar(j)
63        in_this = find(ismembc(all_lmi_variables,blocks{j}.lmi_variables));
64        dummy = [1 1+in_this];
65        [i2,j2,s2] = find(blocks{j}.basis);
66        j2 = dummy(j2);
67        add_shift = size(blocks{j}.basis,1);
68    else
69        [i2,j2,s2] = find(blocks{j}(:));
70        add_shift = size(blocks{j}(:),1);
71    end
72        basis_i = [basis_i;i2(:)+shft];
73        basis_j = [basis_j;j2(:)];
74        basis_s = [basis_s;s2(:)];
75        shft = shft + add_shift;   
76end
77basis = sparse(basis_i,basis_j,basis_s,sum(m)*n,1+length(all_lmi_variables));
78
79y.dim(1) = n;
80y.dim(2) = sum(m);
81y.basis = basis;
82y.lmi_variables = all_lmi_variables;
83
Note: See TracBrowser for help on using the repository browser.