time | Calls | line |
---|
| | 1 | function [b,varargout] = subsref(t,s)
|
| | 2 | %SUBSREF Subscripted reference for a table.
|
| | 3 | % B = SUBSREF(T,S) is called for the syntax T(I,J), T{I,J}, or T.VAR
|
| | 4 | % when T is a table. S is a structure array with the fields:
|
| | 5 | % type -- character vector containing '()', '{}', or '.' specifying the
|
| | 6 | % subscript type.
|
| | 7 | % subs -- Cell array or character vector containing the actual subscripts.
|
| | 8 | %
|
| | 9 | % B = T(I,J) returns a table B that contains a subset of the rows and
|
| | 10 | % variables in the table T. I and J are positive integers, vectors of
|
| | 11 | % positive integers, row/variable names, cell arrays containing one or
|
| | 12 | % more row/variable names, or logical vectors. B contains the same
|
| | 13 | % property values as T, subsetted for rows or variables where
|
| | 14 | % appropriate.
|
| | 15 | %
|
| | 16 | % B = T{I,J} returns an array B created as the horizontal concatenation
|
| | 17 | % of the table variables specified by J, containing only those rows
|
| | 18 | % specified by I. SUBSREF throws an error if the types of the variables
|
| | 19 | % are not compatible for concatenation. I and J are positive integers,
|
| | 20 | % vectors of positive integers, row/variable names, cell arrays
|
| | 21 | % containing one or more row/variable names, or logical vectors. T{I,J}
|
| | 22 | % may also be followed by further subscripting as supported by the
|
| | 23 | % variable.
|
| | 24 | %
|
| | 25 | % B = T.VAR, T.(VARNAME), or T.(VARINDEX) returns a table variable. VAR
|
| | 26 | % is a variable name literal, VARNAME is a character variable containing
|
| | 27 | % a variable name, or VARINDEX is a positive integer. T.VAR, T.(VARNAME),
|
| | 28 | % or T.(VARINDEX) may also be followed by further subscripting as supported
|
| | 29 | % by the variable. In particular, T.VAR(ROWNAMES,...), T.VAR{ROWNAMES,...},
|
| | 30 | % etc. (when supported by VAR) provide subscripting into a table variable
|
| | 31 | % using row names.
|
| | 32 | %
|
| | 33 | % P = T.PROPERTIES.PROPERTYNAME returns a table property. PROPERTYNAME is
|
| | 34 | % 'RowNames', 'VariableNames', 'Description', 'VariableDescriptions',
|
| | 35 | % 'VariableUnits', 'DimensionNames', or 'UserData'. T.PROPERTIES.PROPERTYNAME
|
| | 36 | % may also be followed by further subscripting as supported by the property.
|
| | 37 | %
|
| | 38 | % LIMITATIONS:
|
| | 39 | %
|
| | 40 | % Subscripting expressions such as
|
| | 41 | % T.CellVar{1:2},
|
| | 42 | % T.StructVar(1:2).field, or
|
| | 43 | % T.Properties.RowNames{1:2}
|
| | 44 | % are valid, but result in SUBSREF returning multiple outputs in the form
|
| | 45 | % of a comma-separated list. If you explicitly assign to output arguments
|
| | 46 | % on the LHS of an assignment, for example,
|
| | 47 | % [cellval1,cellval2] = T.CellVar{1:2},
|
| | 48 | % those variables will receive the corresponding values. However, if there
|
| | 49 | % are no output arguments, only the first output in the comma-separated
|
| | 50 | % list is returned.
|
| | 51 | %
|
| | 52 | % See also TABLE, SUBSASGN.
|
| | 53 |
|
| | 54 | % Copyright 2012-2018 The MathWorks, Inc.
|
0.055 | 1134771 | 55 | try
|
| | 56 | % Table subsref most often returns one output, but all three modes might
|
| | 57 | % also return zero or multiple outputs (this is possible even when the
|
| | 58 | % subscripting begins with parens, e.g. t(i,:).Var{:}). subsref's output
|
| | 59 | % args are defined as [b,varargout] so the nargout==1 case can avoid
|
| | 60 | % varargout, although that adds complexity to the nargout==0 case. See
|
| | 61 | % comments below.
|
| | 62 | %
|
| | 63 | % nargout == 0 when the callsite has no LHS, and either (1) the subscripting
|
| | 64 | % ends in parens and should return one value (numArgumentsFromSubscript
|
| | 65 | % isn't called for parens), or (2) the subscripting ends in dot or braces
|
| | 66 | % and numArgumentsFromSubscript determines that there is no output (need to
|
| | 67 | % do the subscripting call even in this case, to get any error handling that
|
| | 68 | % might happen).
|
| | 69 | %
|
| | 70 | % nargout > 1 when the callsite explicitly asks for multiple outputs, or
|
| | 71 | % when the callsite has no LHS and the subscripting ends in dot or braces
|
| | 72 | % and numArgumentsFromSubscript determines the number of outputs.
|
| | 73 |
|
1.392 | 1134771 | 74 | switch s(1).type
|
0.429 | 1134771 | 75 | case '()'
|
0.004 | 70592 | 76 | if nargout == 1
|
12.822 | 70592 | 77 | b = t.subsrefParens(s);
|
| | 78 | elseif nargout > 1
|
| | 79 | [b,varargout{1:nargout-1}] = t.subsrefParens(s);
|
| | 80 | else % nargout == 0
|
| | 81 | % Let varargout bump magic capture either one output (A) or zero
|
| | 82 | % outputs (B). It would be nice to combine (A) with the simple
|
| | 83 | % nargout==1 case (they both return one output), but there's no
|
| | 84 | % fast/simple way to distinguish (A) from (B), so both rely on
|
| | 85 | % varargout. [b,varargout{1:nargout-1}] won't work here, there may
|
| | 86 | % not _be_ an output to assign to b.
|
| | 87 | [varargout{1:nargout}] = t.subsrefParens(s);
|
| | 88 | if isempty(varargout)
|
| | 89 | % Nothing to return
|
| | 90 | else
|
| | 91 | % Shift the return value into the first output arg.
|
| | 92 | b = varargout{1};
|
| | 93 | varargout = {}; % never any additional values
|
| | 94 | end
|
0.004 | 70592 | 95 | end
|
0.266 | 1064179 | 96 | case '{}'
|
0.002 | 37754 | 97 | if nargout == 1
|
2.721 | 37754 | 98 | b = t.subsrefBraces(s);
|
| | 99 | elseif nargout > 1
|
| | 100 | [b,varargout{1:nargout-1}] = t.subsrefBraces(s);
|
| | 101 | else % nargout == 0
|
| | 102 | % See comments in the parens case.
|
| | 103 | [varargout{1:nargout}] = t.subsrefBraces(s);
|
| | 104 | if isempty(varargout)
|
| | 105 | % Nothing to return
|
| | 106 | else
|
| | 107 | % Shift the return value into the first output arg.
|
| | 108 | b = varargout{1};
|
| | 109 | varargout = {}; % never any additional values
|
| | 110 | end
|
0.002 | 37754 | 111 | end
|
0.045 | 1026425 | 112 | case '.'
|
0.050 | 1026425 | 113 | if nargout == 1
|
26.704 | 1026425 | 114 | b = t.subsrefDot(s);
|
| | 115 | elseif nargout > 1
|
| | 116 | [b,varargout{1:nargout-1}] = t.subsrefDot(s);
|
| | 117 | else % nargout == 0
|
| | 118 | % See comments in the parens case.
|
| | 119 | [varargout{1:nargout}] = t.subsrefDot(s);
|
| | 120 | if isempty(varargout)
|
| | 121 | % Nothing to return
|
| | 122 | else
|
| | 123 | % Shift the return value into the first output arg.
|
| | 124 | b = varargout{1};
|
| | 125 | varargout = {}; % never any additional values
|
| | 126 | end
|
0.038 | 1026425 | 127 | end
|
0.109 | 1134771 | 128 | end
|
| | 129 | catch ME
|
| | 130 | throwAsCaller(ME)
|
0.205 | 1134771 | 131 | end
|
Other subfunctions in this file are not included in this listing.