%% Write Tabular Data Containing Arbitrary Variable Names
% You can write tabular data containing variable names that have any characters, including spaces and non-ASCII characters. Create a table with arbitrary variable names and write the table to a text file. Then, read the tabular data back while preserving the original variable names.
% Create a table containing three variables with arbitrary variable names. The first and third variable names contain spaces and non-ASCII characters.

LastName = {'Sanchez';'Johnson';'Li';'Diaz';'Brown'};
Age = [38;43;38;40;49];
Smoker = logical([1;0;1;0;1]);
varNames = {'Last Name','Age','Smoker (1 or 0)'};
T = table(LastName,Age,Smoker,'VariableNames',varNames)

% Write the data to the file 'sampletable.txt'.

writetable(T,'sampletable.txt')

%
% Read the tabular data back using readtable. By default, MATLAB®  converts any variable names that include spaces and non-ASCII characters into valid MATLAB® identifiers. For example, MATLAB® converts the variable names 'Last Name' to 'LastName', and 'Smoker (1 or 0)' to 'Smoker_1or0_'. To read the tabular data while preserving variable names, set the 'PreserveVariableNames' parameter to true.

T_preserve = readtable('sampletable.txt','PreserveVariableNames',true)

% Copyright 2019 The MathWorks, Inc.