%% Define Import Options for Variables in Delimited Text File
% Define an import options object to read multiple variables from patients.dat.
% Based on the contents of your file, define these variable properties: names, types, delimiter character, data starting location, and the extra column rule.

varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
delimiter = ',';
dataStartLine = 2;
extraColRule = 'ignore';

% Use the delimitedTextImportOptions function and your variable information to initialize the import options object opts.

opts = delimitedTextImportOptions('VariableNames',varNames,...
                                'VariableTypes',varTypes,...
                                'Delimiter',delimiter,...
                                'DataLines', dataStartLine,...
                                'ExtraColumnsRule',extraColRule); 

% Use the preview function with the import options object to preview the data.

preview('patients.dat',opts)

% Import the data using readtable.

T = readtable('patients.dat',opts);
whos T

% Copyright 2018 The MathWorks, Inc.