time | Calls | line |
---|
| | 195 | function obj = setLabels(obj,newLabels,subscripts,fixDups,fixEmpties,fixIllegal)
|
| | 196 | %SETLABELS Modify, overwrite, or remove a tabularDimension's labels.
|
< 0.001 | 24 | 197 | if isstring(newLabels)
|
| | 198 | % cannot use convertStringsToChars because scalar string
|
| | 199 | % must convert to cellstr, not char vector.
|
| | 200 | newLabels = cellstr(newLabels);
|
< 0.001 | 24 | 201 | end
|
< 0.001 | 24 | 202 | if nargin < 6
|
| | 203 | % Should illegal labels be modified to make them legal?
|
< 0.001 | 24 | 204 | fixIllegal = false;
|
< 0.001 | 24 | 205 | if nargin < 5
|
| | 206 | % Should empty labels be filled in wth default labels?
|
< 0.001 | 24 | 207 | fixEmpties = false;
|
< 0.001 | 24 | 208 | if nargin < 4
|
| | 209 | % Should duplicate labels be made unique?
|
< 0.001 | 24 | 210 | fixDups = false;
|
< 0.001 | 24 | 211 | end
|
< 0.001 | 24 | 212 | end
|
< 0.001 | 24 | 213 | end
|
| | 214 |
|
| | 215 | % Subscripts equal to [] denotes a full assignment while the edge case of a
|
| | 216 | % partial assignment to zero labels requires a 1x0 or 0x1 empty.
|
< 0.001 | 24 | 217 | fullAssignment = (nargin == 2) || isequal(subscripts,[]);
|
< 0.001 | 24 | 218 | if fullAssignment % replacing all labels
|
0.001 | 24 | 219 | indices = 1:obj.length;
|
| | 220 | elseif obj.hasLabels % replacing some labels
|
| | 221 | indices = obj.subs2inds(subscripts);
|
| | 222 | if islogical(indices)
|
| | 223 | % subs2inds leaves logical untouched, validateAndAssignLabels requires indices
|
| | 224 | indices = find(indices);
|
| | 225 | end
|
| | 226 | else % don't allow a subscripted assignment to an empty label property
|
| | 227 | assert(false,'Partial/Subscripted assignment to empty label is not supported');
|
< 0.001 | 24 | 228 | end
|
| | 229 |
|
| | 230 | % Check the type of the new labels, and convert them to the canonical type as
|
| | 231 | % necessary (and allowed). If this is a full assignment of a 0x0, and removing
|
| | 232 | % the labels is allowed, validateLabels leaves the shape alone, otherwise it
|
| | 233 | % reshapes to a vector of the appropriate orientation.
|
0.036 | 24 | 234 | obj = obj.validateAndAssignLabels(newLabels,indices,fullAssignment,fixDups,fixEmpties,fixIllegal);
|
< 0.001 | 24 | 235 | end
|
Other subfunctions in this file are not included in this listing.