% Lecture 6th Nov

%%
% Let's compare two matrices
A = [1 3 2; 8 7 4]

B = [6 6 6; 9 9 9]

% compare A to B
A < B

% we can compare one of the arrays to a scalar
A > 5

%% Create cell array
% create a 2-by3 cel  array of text and numeric data
M = {'one', 'two', 'three'; 1, 2, 3}
% access data in cell array
M(1:2,1:2)

%% Extract information 
% consider the following list
contacts = { ...
'Harris Bern, OH hparker@hmail.com'; ...
'Jane Paris, CA jane_borbon@horizon.net'; ...
'Mose  Munich, VA mose_hillan@hmail.net'; ...
'Norah  Paris, FL norah_kevin@horizon.net'; ...
'Jackson London, CO jackson_bel@mymail.com'};

% each individual's record occupies a row of the cell array

% We can extract row 2 the list
contacts{2}

% we identify a unique pattern in the text 
email = '[a-z_]+@[a-z]+\.(com|net)';

% search for the email of all individuals in the list 
regexp(contacts, email, 'match')
% search for the email of the fourth individual in the list 
regexp(contacts{4}, email, 'match')

%% Plot 
% use line styles from a 2-by-3 cell array R

x =-pi:pi/10:pi;
y = tan(sin(x))- sin(tan(x));

R(:,1) = {'Linewidth';2};
R(:,2) = {'MarkerEdgeColor';'k'};
R(:,3) = {'MarkerEdgeColor';'g'};

plot(x,y,'--rs',R{:})

%% Create a calendar duration 
S = calmonths(3)
S1 = caldays(3)
S2 = calweeks(3)
S3 = calquarters(3)
S4 = calyears(3)
% consider two dates  June 28, 2018 at 6 am and June 28, 2018 at 7 am
t = datetime(2018,6,28,6:7,0,0)
% add calendar durations to datetime to obtain a new date
t2 = t + S
t3 = t + S1
t4 = t + S2
t5 = t + S3
t6 = t + S4



%% 

A = [  1   5   8; 
       -3 NaN  14; 
        0   6 NaN ]
    
% create a function called remove_nan_rows     
remove_nan_rows(A);
  
   
x=5;

disp(['the number is ',num2str(x)])

% create a function called functionname     
functionname(1,6);

% define function y
y =@sin

y(pi)
y(0)
y(pi/2)

% define function with only one input
y=@(x)sin(cos(x))

y(3)

% define function with multiple input
y=@(x,z)sin(cos(x+z))

y(3,6)