www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SetDataTypesForMultipleVariablesExample.m
%% Set Data Types for Multiple Variables % Use |detectImportOptions| to create import options, set % multiple variable data types, and then read the data using % |readtable|. %% % Create an options object. opts = detectImportOptions('patients.xls'); %% % Examine the current (detected) data types of the variables. disp([opts.VariableNames' opts.VariableTypes']) %% % Change the data type of multiple variables depending on your import needs. opts = setvartype(opts,{'LastName','Gender','Location',... 'Smoker','SelfAssessedHealthStatus'},'string'); opts = setvartype(opts,{'Age','Height','Weight',... 'Systolic','Diastolic'},'single'); %% % Examine the updated data types of the variables. disp([opts.VariableNames' opts.VariableTypes']) %% % Import the variables with their updated types using |readtable|. T = readtable('patients.xls',opts);