time | Calls | line |
---|
| | 1 | function t = subsasgn(t,s,b)
|
| | 2 | %SUBSASGN Subscripted assignment to a table.
|
| | 3 | % T = SUBSASGN(T,S,B) is called for the syntax T(I,J)=B, T{I,J}=B, or
|
| | 4 | % T.VAR=B 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 | % T(I,J) = B assigns the contents of the table B to a subset of the rows
|
| | 10 | % and variables in the table T. I and J are positive integers, vectors
|
| | 11 | % of positive integers, row/variable names, cell arrays containing one or
|
| | 12 | % more row/variable names, or logical vectors. The assignment does not
|
| | 13 | % use row names, variable names, or any other properties of B to modify
|
| | 14 | % properties of T; however properties of T are extended with default
|
| | 15 | % values if the assignment expands the number of rows or variables in T.
|
| | 16 | % Elements of B are assigned into T by position, not by matching names.
|
| | 17 | %
|
| | 18 | % T{I,J} = B assigns the values in the array B into elements of the table
|
| | 19 | % T. I and J are positive integers, or logical vectors. Columns of B
|
| | 20 | % are cast to the types of the target variables if necessary. If the
|
| | 21 | % table elements already exist, T{I,J} may also be followed by further
|
| | 22 | % subscripting as supported by the variable.
|
| | 23 | %
|
| | 24 | % T.VAR = B, T.(VARNAME) = B, or T.(VARINDEX) = B assigns B to a table
|
| | 25 | % variable. VAR is a variable name literal, VARNAME is a character
|
| | 26 | % variable containing a variable name, or VARINDEX is a positive integer.
|
| | 27 | % If the table variable already exists, the assignment completely
|
| | 28 | % replaces that variable. To assign into an element of the variable,
|
| | 29 | % T.VAR, T.(VARNAME), or T.(VARINDEX) may be followed by further
|
| | 30 | % subscripting as supported by the variable. In particular,
|
| | 31 | % T.VAR(ROWNAMES,...) = B, T.VAR{ROWNAMES,...} = B, etc. (when supported
|
| | 32 | % by VAR) provide assignment into a table variable using row names.
|
| | 33 | %
|
| | 34 | % T.PROPERTIES.PROPERTYNAME = P assigns to a table property. PROPERTYNAME
|
| | 35 | % is 'RowNames', 'VariableNames', 'Description', 'VariableDescriptions',
|
| | 36 | % 'VariableUnits', 'DimensionNames', or 'UserData'. To assign into an element
|
| | 37 | % of the property, T.PROPERTIES.PROPERTYNAME may also be followed by further
|
| | 38 | % subscripting as supported by the property.
|
| | 39 | %
|
| | 40 | % LIMITATIONS:
|
| | 41 | %
|
| | 42 | % You cannot assign multiple values into a table variable or property using
|
| | 43 | % assignments such as
|
| | 44 | % [A.CellVar{1:2}] = deal(B1,B2),
|
| | 45 | % [A.StructVar(1:2).field] = deal(B1,B2), or
|
| | 46 | % [A.Properties.ObsNames{1:2}] = deal(B1,B2)
|
| | 47 | % Use multiple assignments of the form A.CellVar{1} = B1 instead.
|
| | 48 | %
|
| | 49 | % See also TABLE, SUBSREF.
|
| | 50 |
|
| | 51 | % Copyright 2012-2019 The MathWorks, Inc.
|
| | 52 |
|
| | 53 | % Avoid unsharing of shared-data copy across function call boundary
|
| | 54 | import matlab.lang.internal.move
|
| | 55 |
|
< 0.001 | 8 | 56 | try
|
< 0.001 | 8 | 57 | creating = isnumeric(t) && isequal(t,[]);
|
< 0.001 | 8 | 58 | if creating
|
| | 59 | t = b.cloneAsEmpty;
|
< 0.001 | 8 | 60 | end
|
| | 61 |
|
< 0.001 | 8 | 62 | switch s(1).type
|
< 0.001 | 8 | 63 | case '()'
|
| | 64 | t = move(t).subsasgnParens(s,b,creating);
|
< 0.001 | 8 | 65 | case '{}'
|
| | 66 | %assert(~creating)
|
| | 67 | t = move(t).subsasgnBraces(s,b);
|
< 0.001 | 8 | 68 | case '.'
|
| | 69 | %assert(~creating)
|
0.030 | 8 | 70 | t = move(t).subsasgnDot(s,b);
|
< 0.001 | 8 | 71 | end
|
| | 72 | catch ME
|
| | 73 | throwAsCaller(ME)
|
< 0.001 | 8 | 74 | end
|
Other subfunctions in this file are not included in this listing.