[37] | 1 | function F = subsref(F,Y) |
---|
| 2 | %subsref Overloaded indexing |
---|
| 3 | |
---|
| 4 | % Author Johan Löfberg |
---|
| 5 | % $Id: subsref.m,v 1.4 2005/02/04 10:10:27 johanl Exp $ |
---|
| 6 | |
---|
| 7 | switch Y(1).type |
---|
| 8 | case '()' |
---|
| 9 | thelmi = Y.subs{1}; |
---|
| 10 | |
---|
| 11 | % Early bail to optmize code for standard case |
---|
| 12 | if isa(thelmi,'double') % &(isa(F,'lmi') % |
---|
| 13 | |
---|
| 14 | else |
---|
| 15 | if ~(isa(F,'lmi') & (isa(thelmi,'logical') | isa(thelmi,'double') | isa(thelmi,'char'))) |
---|
| 16 | error('First argument should be an lmi object and second argument integer or string') |
---|
| 17 | end |
---|
| 18 | |
---|
| 19 | % If indexed using handle, convert to index |
---|
| 20 | if isa(thelmi,'char') |
---|
| 21 | thelmitemp = []; |
---|
| 22 | for i = 1:size(F.clauses,2) |
---|
| 23 | if strcmp(F.clauses{i}.handle,thelmi) |
---|
| 24 | thelmitemp=[thelmitemp i]; |
---|
| 25 | end |
---|
| 26 | end |
---|
| 27 | if isempty(thelmitemp) |
---|
| 28 | em = ['LMI ''' thelmi ''' not available.']; |
---|
| 29 | error(em) |
---|
| 30 | else |
---|
| 31 | thelmi = thelmitemp; |
---|
| 32 | end |
---|
| 33 | end |
---|
| 34 | |
---|
| 35 | if islogical(thelmi) |
---|
| 36 | thelmi = double(find(thelmi)); |
---|
| 37 | end |
---|
| 38 | |
---|
| 39 | end |
---|
| 40 | |
---|
| 41 | % Checks so that it exist |
---|
| 42 | if any((thelmi<1)) | any((thelmi>size(F.clauses,2))) |
---|
| 43 | em = ['LMI #' num2str(thelmi) ' not available.']; |
---|
| 44 | error(em) |
---|
| 45 | end |
---|
| 46 | |
---|
| 47 | % These indicies |
---|
| 48 | j = thelmi; |
---|
| 49 | ineqs = find(j<=size(F.clauses,2)); |
---|
| 50 | ineqs_j = j(ineqs); |
---|
| 51 | |
---|
| 52 | if isempty(ineqs_j) |
---|
| 53 | F.clauses = {}; |
---|
| 54 | F.LMIid = []; |
---|
| 55 | else |
---|
| 56 | F.clauses = F.clauses(ineqs_j); |
---|
| 57 | F.LMIid = F.LMIid(ineqs_j); |
---|
| 58 | end |
---|
| 59 | case '{}' |
---|
| 60 | switch length(Y) |
---|
| 61 | case 1 |
---|
| 62 | if length(Y.subs)>1 |
---|
| 63 | error('Only one-dimensional indexing of set objects allowed'); |
---|
| 64 | end |
---|
| 65 | if Y.subs{1}>length(F.clauses) |
---|
| 66 | em = ['LMI #' num2str(Y.subs{1}) ' not available.']; |
---|
| 67 | error(em) |
---|
| 68 | error('Index exceeds set dimension.') |
---|
| 69 | end |
---|
| 70 | F = F.clauses{Y.subs{1}}.data; |
---|
| 71 | case 2 |
---|
| 72 | F = F.clauses{Y(1).subs{1}}.data; |
---|
| 73 | F = subsref(F,Y(2)); |
---|
| 74 | otherwise |
---|
| 75 | error('Indexing type not supported'); |
---|
| 76 | end |
---|
| 77 | otherwise |
---|
| 78 | error('Indexing type not supported'); |
---|
| 79 | end |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | |
---|