%% Convert Table with Row Names to Structure
% Create a table, T, that includes row names.

T = table(categorical({'M';'M';'F';'F';'F'}),[38;43;38;40;49],...
    [124 93;109 77; 125 83; 117 75; 122 80],...
    'VariableNames',{'Gender' 'Age' 'BloodPressure'},...
    'RowNames',{'Smith' 'Johnson' 'Williams' 'Jones' 'Brown'})

%
% Convert T to a scalar structure.

S = table2struct(T,'ToScalar',true)

%
% Add a field for the row names from the table.

S.RowNames = T.Properties.RowNames

% If S is a nonscalar structure, use [S.RowNames] = T.Properties.RowNames{:} to include a field with the row names from the table.
% Copyright 2012 The MathWorks, Inc.