time | Calls | line |
---|
| | 1 | function s = substruct(type,subs,varargin)
|
| | 2 | %SUBSTRUCT Create structure argument for SUBSREF or SUBSASGN.
|
| | 3 | % S = SUBSTRUCT(TYPE1,SUBS1,TYPE2,SUBS2,...) creates a structure with
|
| | 4 | % the fields required by an overloaded SUBSREF or SUBSASGN method. Each
|
| | 5 | % TYPE must be one of '.', '()', or '{}'. The corresponding SUBS
|
| | 6 | % argument must be either a field name (for the '.' type) or a cell
|
| | 7 | % array containing the index vectors (for the '()' or '{}' types). The
|
| | 8 | % output S is a structure array containing the fields:
|
| | 9 | % type -- subscript types '.', '()', or '{}'
|
| | 10 | % subs -- actual subscript values (field names or cell arrays
|
| | 11 | % of index vectors)
|
| | 12 | %
|
| | 13 | % For example, to call SUBSREF with parameters equivalent to the syntax
|
| | 14 | % B = A(i,j).field
|
| | 15 | % use
|
| | 16 | % S = substruct('()',{i j},'.','field');
|
| | 17 | % B = subsref(A,S);
|
| | 18 | % Similarly,
|
| | 19 | % subsref(A, substruct('()',{1:2, ':'})) performs A(1:2,:)
|
| | 20 | % subsref(A, substruct('{}',{1 2 3})) performs A{1,2,3}.
|
| | 21 | %
|
| | 22 | % See also SUBSREF, SUBSASGN, NUMARGUMENTSFROMSUBSCRIPT.
|
| | 23 |
|
| | 24 | % Copyright 1984-2019 The MathWorks, Inc.
|
| | 25 |
|
< 0.001 | 788 | 26 | nlevels = nargin / 2;
|
< 0.001 | 788 | 27 | if nlevels < 1
|
| | 28 | error(message('MATLAB:substruct:nargin'))
|
< 0.001 | 788 | 29 | elseif rem(nlevels,1)
|
| | 30 | error(message('MATLAB:substruct:narginOdd'))
|
< 0.001 | 788 | 31 | end
|
| | 32 |
|
0.002 | 788 | 33 | s.type = type;
|
0.002 | 788 | 34 | s.subs = subs;
|
< 0.001 | 788 | 35 | if nlevels > 1
|
| | 36 | s(2:nlevels) = struct('type',varargin(1:2:end),'subs',varargin(2:2:end));
|
< 0.001 | 788 | 37 | end
|