%% Convert Array and Select Data by Category
% Create a categorical array that has weather station labels. Add it to a table of temperature readings. Then use the categories to select temperature readings by station.
% First, create arrays containing temperature readings, dates, and station labels.

Temps = [58; 72; 56; 90; 76];
Dates = {'2017-04-17';'2017-04-18';'2017-04-30';'2017-05-01';'2017-04-27'};
Stations = {'S1';'S2';'S1';'S3';'S2'};

%
% Convert Stations to a categorical array.

Stations = categorical(Stations)

%
% Display the categories. The three stations labels are categories.

categories(Stations)

%
% Create a table that contains the temperatures, dates, and station labels.

T = table(Temps,Dates,Stations)

%
% Display the readings taken from station S2. You can use the == operator to find the values of Station that equal S2. Then use logical indexing to select the table rows that have data from station S2.

TF = (T.Stations == 'S2');
T(TF,:)

%
%
% Copyright 2012 The MathWorks, Inc.