%% Element by element manipulations of arrays
clear
close all

x = [3 6 3 4];
y = [4 9 2 0];

x+y
x*y % Results in an error, can't array multiply with these dimensions

% Use a dot before the multiplication to tell matlab to element multiply
x.*y

2^x % Results in error again
2.^x % Gives squared values of each element

%% Matrices - arrays with more than 1 dimension
clear 
close all

% Manually define a matrix
a = [1 2; 3 4]
b = [3 1; 4 2]
% a and b are 2x2 matrix. 

b = det(a)
c = a+b
d = a*a

% Address different elements
a(1,2)
a(2,2) = 5

max(a)
min(a)

%% Just for fun, lets play around with sound
clear 
close all

Fs = 44100; % Sampling Frequency
t = (1/Fs:1/Fs:3); % A 3 second note
freq = 440; % An A note
A = cos(2*pi*freq*t); % An A note is 440 Hz

figure
plot(t(1:1300),A(1:1300))
xlabel('Time (sec)')
ylabel('Amplitude')

sound(A,Fs)

% Try a different note
freq2 = 523; % C is 523 Hz
C = cos(2*pi*freq2*t);

sound(C,Fs)


% Try interfering the waves
int = A+C;

sound(int,Fs)

figure
plot(t(1:1600),int(1:1600))
xlabel('Time (sec)')
ylabel('Amplitude')

%% Types of variables
clear
close all

% We know about numbers.  Easy to store them as variables, arrays, and
% matrices

a = 7
b = 55
c = 1:7

% We can also add characters.  These are obviously letters.  Strings are
% defined by using single apostrophe

d = 'hello world'
e = 'Quantitative optical imaging rocks'

% Character arrays are accessed exactly the same way as numerical arrays
d(1)
d(7)
e(1:7)
e([1 3 4 5 7])


% Structures are a class that can hold different types of data, with each
% one having a name

students.name = 'Johnny Appleseed'
students.age  = 24
students.grade = 'A'

students(2).name = 'Ralphie Buffalo'
students(2).age = 7
% If you look at variable editor, you can see all these inserted into a
% matrix
students(2).grade = 'C';

students.name
students.grade


%% Loading in data from hard drive
clear
close all

dir

a = dir
a.name
a.date

cd ..
cd('Matlab code')

img = imread('D:\Users\JoelKralj\Dropbox\Dropbox\Camera Uploads\2015-08-21 11.39.56.jpg');
figure
imshow(img)

size(img)

figure
imshow(img(:,:,2))

