%% Extract Data Using Dot Notation and Logical Values
% Create a table from the patients MAT-file. Then use dot notation to extract data from table variables. You can also index using logical indices generated from values in a table variable that meet a condition.

load patients

T = table(Age,Gender,Height,Weight,Smoker,...
    'RowNames',LastName);

%
%% Extract Data from Variable
% To extract data from one variable, use dot notation. Extract numeric values from the variable Weight. Then plot a histogram of those values.

histogram(T.Weight)
title('Patient Weight')

%
% T.Weight is a double-precision column vector with 100 rows.
%
%% Select Rows with Logical Indexing
% You can index into an array or a table using an array of logical indices. Typically, you use a logical expression that determines which values in a table variable meet a condition. The result of the expression is an array of logical indices.
% For example, create logical indices matching patients whose age is less than 40.

rows = T.Age < 40

%
% To extract heights for patients whose age is less than 40, index into the Height variable using rows. There are 56 patients younger than 40.

T.Height(rows)

%
% You can index into a table with logical indices. Display the rows of T for the patients who are younger than 40.

T(rows,:)

%
% You can match multiple conditions with one logical expression. Display the rows for smoking patients younger than 40.

rows = (T.Smoker==true & T.Age<40);
T(rows,:)

% Copyright 2019 The MathWorks, Inc.