%% Lab 7: Data Structures - Wednesday, 2016-03-23
% This lab will focus on the use of two new data structures: cell arrays
% and structures.

%% Cell Arrays
% Let's begin by creating a cell array. Your cell array should contain at
% least three different data types as a row vector. Use the disp function
% to print your cell array

cellvec = {true, 'fun', [1 4 19]};
disp(cellvec);

%% Referencing in Cell Arrays
% Use the class function to see the difference between indexing the second
% element of your cell array with {} and ().

class(cellvec{2})
class(cellvec(2))

%% Removing and Replacing Elements in a Cell Array
% Remove the first element of your cell array. Then, replace the second
% element of your new cell array with the scalar 11. Think about which
% referencing method is necessary for each action.

cellvec(1) = [];
cellvec{2} = 11;
disp(cellvec)

%% Adding Elements to a Cell Array
% Add a new cell to the end of your cell array that contains the logical
% value true.

cellvec{end+1} = true;
disp(cellvec)


%% Structures
% Create a structure that represents information about you. It should be
% initialized with fields for your name, birthday, and eye color. Display
% the structure using the disp function.

jane = struct('name', 'jane', 'birthday', '01/02/03', 'eye', 'brown');
disp(jane)


%% Referencing Fields in a Structure
% Use the fprintf function and your structure to print a statement that
% describes you. For example, 'Jane was born 01/02/03 and her eye color is
% brown.'

fprintf('%s was born %s and her eye color is %s.\n', jane.name, jane.birthday, jane.eye)

%% Adding a Field to a Structure
% Let's add a field to your structure that holds your current age.

jane.age = 13;
disp(jane)

%% Removing Fields from a Structure
% You decide that you don't want to have your age and birthday listed.
% Remove those fields from your structure.

jane = rmfield(jane, 'birthday');
jane = rmfield(jane, 'age');
disp(jane)

%% Displaying Fields in a Structure
% Use the fieldnames function to display all remaining fields in your
% structure

fieldnames(jane)

%% Nested Data Structures
% Create a new field to your structure that uses a cell array to list your
% favorite animals. Use the disp function to print only the first animal in
% your cell array

jane.favanimals = {'tigers', 'dogs', 'owls'};
disp(jane)
disp(jane.favanimals{1})





