time | Calls | line |
---|
| | 262 | function opts = setvartype(opts,varargin)
|
| | 263 | %setvartype
|
| | 264 | % OPTS = setvartype(OPTS,TYPE) set all variables to the
|
| | 265 | % specified TYPE by name.
|
| | 266 | %
|
| | 267 | % OPTS = setvartype(OPTS,NAMES,TYPE) set the variables to the
|
| | 268 | % specified TYPE by name. NAMES can be a character vector or a
|
| | 269 | % cell array of character vectors.
|
| | 270 | %
|
| | 271 | % OPTS = setvartype(OPTS,INDEX,TYPE) set the variables to the
|
| | 272 | % specified TYPE by index. INDEX must be a vector of positive integers with
|
| | 273 | % values between 1 and the length of the VARIABLENAMES property of OPTS.
|
| | 274 | %
|
| | 275 | % TYPE can be any numeric type, 'string, 'char',
|
| | 276 | % 'datetime', 'duration, 'categorical' or 'logical'.
|
| | 277 | %
|
| | 278 | % See also
|
| | 279 | % setvaropts, getvaropts, detectImportOptions
|
| | 280 | % matlab.io.VariableImportOptions
|
| | 281 |
|
| | 282 | import matlab.io.internal.validators.validateCellStringInput;
|
| | 283 |
|
< 0.001 | 2 | 284 | narginchk(2,3);
|
< 0.001 | 2 | 285 | if nargout == 0
|
| | 286 | error(message('MATLAB:textio:io:NOLHS','setvartype','setvartype'))
|
< 0.001 | 2 | 287 | end
|
< 0.001 | 2 | 288 | v_opts = opts.fast_var_opts;
|
< 0.001 | 2 | 289 | if nargin == 2
|
| | 290 | % setvartype(OPTS,TYPE) syntax
|
| | 291 | selection = 1:v_opts.numVars;
|
| | 292 | type = varargin{1};
|
< 0.001 | 2 | 293 | elseif isnumeric(varargin{1})
|
| | 294 | selection = varargin{1};
|
| | 295 | type = varargin{2};
|
< 0.001 | 2 | 296 | elseif islogical(varargin{1})
|
< 0.001 | 2 | 297 | selection = find(varargin{1});
|
< 0.001 | 2 | 298 | type = varargin{2};
|
| | 299 | else
|
| | 300 | selection = validateCellStringInput(convertStringsToChars(varargin{1}), 'SELECTION');
|
| | 301 | if iscell(selection) || ischar(selection)
|
| | 302 | % Get the appropriate numeric indices and error for unknown variable names.
|
| | 303 | selection = opts.getNumericSelection(selection);
|
| | 304 | end
|
| | 305 | type = convertStringsToChars(varargin{2});
|
< 0.001 | 2 | 306 | end
|
| | 307 | % Convert to cellstr
|
0.001 | 2 | 308 | try type = cellstr(type); catch
|
| | 309 | error(message('MATLAB:textio:textio:InvalidStringOrCellStringProperty','TYPES'));
|
< 0.001 | 2 | 310 | end
|
| | 311 |
|
| | 312 | % Expand scalar
|
< 0.001 | 2 | 313 | if isscalar(type)
|
< 0.001 | 2 | 314 | type = repmat(type,size(selection));
|
| | 315 | elseif numel(type) ~= numel(selection)
|
| | 316 | error(message('MATLAB:textio:io:MismatchVarTypes'))
|
< 0.001 | 2 | 317 | end
|
| | 318 |
|
| | 319 | % Set the underlying types
|
< 0.001 | 2 | 320 | try
|
| | 321 | %opts.fast_var_opts = v_opts.overrideType(selection,type);
|
< 0.001 | 2 | 322 | opts.fast_var_opts = v_opts.setTypes(selection, type);
|
| | 323 | catch ME
|
| | 324 | throw(ME)
|
< 0.001 | 2 | 325 | end
|
< 0.001 | 2 | 326 | end
|
Other subfunctions in this file are not included in this listing.