Rename year directories to allow natural ordering

This commit is contained in:
2023-12-20 03:57:27 +00:00
parent 0ab1f5ad3a
commit 1f7d812b98
1895 changed files with 0 additions and 7188 deletions

View File

@ -0,0 +1,8 @@
clear;
d = roll_2_dice(10000, 100);
[freq, prop] = tabulate_2_dice(d);
disp(freq);
disp(prop);

View File

@ -0,0 +1,7 @@
function d = roll_2_dice(N, seed)
% function to roll 2 dice and return the combination of each device row in a vector
rng(seed);
% generating two 1 * N vectors of 6 simulated dice rolls and adding them
d = randi([1 6], 1, N) + randi([1 6], 1, N);
end

View File

@ -0,0 +1,14 @@
function [freq, prop] = tabulate_2_dice(d)
% function to calculate the frequency and proportion of each outcome based on a set of dice throws
freq = zeros(1,12);
% looping through all the values in d and incrementing the corresponding counter in freq
for i = d
freq(i) = freq(i) + 1;
end
% looping through each index in prop and calculating the proportion pertaining to that index
prop = zeros(1,12);
for i = [1:12]
prop(i) = freq(i) / sum(freq); % proportion of i is the frequency of i divided by the sum of all freqs
end
end

View File

@ -0,0 +1,28 @@
function[push, pop, peek] = mystack()
% function to return handles to the subfunction push, pop, & peek
push = @push;
pop = @pop;
peek = @peek;
end
function [stack] = push(stack, value)
% function to push a value onto the stack at location 1 and return the
% stack
stack = [value; stack];
end
function [stack] = pop(stack)
% function to pop the value at location 1 off the stack and return the
% stack
stack(1) = [];
end
function [value] = peek(stack)
% function to return the top value from the stack (arrau location 1)
% returns NaN if there is no value at location 1
if isempty(stack)
value = NaN;
else
value = stack(1);
end
end

View File

@ -0,0 +1,13 @@
% test script as specified in assignment spec
[push, pop, peek] = mystack();
stack = []
stack = push(stack, 100)
stack = push(stack, 200)
peek(stack)
stack = pop(stack)
peek(stack)

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 KiB

View File

@ -0,0 +1,15 @@
clear;
eng1 = imread("Engineering-Building.jpg");
eng1_gs = pic2grayscale(eng1);
eng1_gs_inv = transform_pic(eng1_gs);
eng1_gs_bin_50 = transform_threshold(eng1_gs,50);
eng1_gs_bin_75 = transform_threshold(eng1_gs,75);
eng1_gs_bin_100 = transform_threshold(eng1_gs,100);
% plotting images
subplot(3,2,1),imshow(eng1),title("Original Picture");
subplot(3,2,2),imshow(eng1_gs),title("Greyscale");
subplot(3,2,3),imshow(eng1_gs_inv),title("Inverted Greyscale");
subplot(3,2,4),imshow(eng1_gs_bin_50),title("Binary Threshold = 50");
subplot(3,2,5),imshow(eng1_gs_bin_75),title("Binary Threshold = 75");
subplot(3,2,6),imshow(eng1_gs_bin_100),title("Binary Threshold = 100");

View File

@ -0,0 +1,17 @@
function [returnImg] = pic2grayscale(img)
% which uses the NTSC Standard transformation to convert RGB to grayscale.
%0.2989 * R + 0.5870 * G + 0.1140 * B
% img to be returned
returnImg = zeros(size(img,1), size(img, 2));
% looping through the RGB image and calculating the grayscale value for
% each pixel in the corresponding returnImg
for i = 1:size(img,1)
for j = 1:size(img,2)
returnImg(i,j) = (0.2989 * img(i,j,1)) + (0.5870 * img(i,j,2)) + (0.1140 * img(i,j,3));
end
end
returnImg = uint8(returnImg);
end

View File

@ -0,0 +1,5 @@
function [img] = transform_pic(img)
% function which converts a 255 colour code to 0, 254 to 1, etc, and 0 to
% 255.
img = 255 - img;
end

View File

@ -0,0 +1,18 @@
function [img] = transform_threshold(img, threshold)
% function which converts the picture to binary format where any value
% above the threshold is white (1), and all values equal to or below are
% black (0).
% looping through each element in the matrix, and setting it to 1 if
% above the threshold, 0 otherwise
for i = 1:numel(img)
if img(i) > threshold
img(i) = 1;
else
img(i) = 0;
end
end
% casting the matrix to type logical once each element is either 1 or 0
img = logical(img);
end

View File

@ -0,0 +1,14 @@
function dydt = shark_tuna_model(t,x)
% function to model the prey-predator population relations over time of
% sharks & tuna
global k; % mentioning global variable x so that it can be used here
dydt = [0; 0];
% dS/dt = k1 S T - k2 S
dydt(1) = k(1)*x(1)*x(2)-k(2)*x(1);
% dT/dt = k3 T -k4 S T
dydt(2) = k(3)*x(2) - k(4) * x(1) * x(2);
end

View File

@ -0,0 +1,12 @@
clear;
global k;
k = [0.015 0.7 0.5 0.01].';
[t,y] = ode45(@shark_tuna_model, [0 50], [100 100]);
plot(t,y);
title("SHARK-TUNA POPULATION DYNAMICS LIMIT CYCLING");
xlabel("TIME");
ylabel("POPULATION NUMBERS");
legend("SHARKS", "TUNA", "Location", "northwest");

View File

@ -0,0 +1,15 @@
function dydt = SIR(t, x, c, i, alpha, beta, gamma)
dydt = [0; 0; 0; 0; 0];
S = x(1);
I = x(2);
R = x(3);
H = x(4);
RH = x(5);
N = S + I + R + H + RH;
dydt(1) = (-c*S) * (I/N) * i;
dydt(2) = (c*S) * (I/N) * i - (alpha*I);
dydt(3) = (alpha*I) - (beta*R);
dydt(4) = (beta*R) - (gamma*H);
dydt(5) = gamma*H;
end

View File

@ -0,0 +1,40 @@
clear;
i = 0.125;
alpha = 0.25;
beta = 0.02;
gamma = 0.10;
time_vec = 0:.25:100;
init_vec = [9999 1 0 0 0];
c = linspace(3, 8, 20);
infected_stock = zeros(length(time_vec), 20);
in_hospital = zeros(length(time_vec), 20);
for loopcounter = 1:20
[t,y] = ode45(@SIR, ...
time_vec, ...
init_vec, ...
odeset, ...
c(loopcounter), ...
i, ...
alpha, ...
beta, ...
gamma);
infected_stock(:, loopcounter) = y(:,2);
in_hospital(:,loopcounter) = y(:,4);
end
subplot(3, 1, 1);
plot(time_vec, infected_stock);
title("Infected Stock");
subplot(3, 1, 2);
plot(time_vec, infected_stock);
title("People in Hospital");
subplot(3,1,3);
scatter(c, max(in_hospital));
title("Contacts v Peak in Hospital");

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,76 @@
clear;
% 1. read in the file and confirm the number of records (336,766)
flights = readtable("Flights.csv");
numRecords = height(flights)
% 2. convert "origin" & "dest" to strings (from cell type)
flights.origin = string(flights.origin);
flights.dest = string(flights.dest);
% 3. check the number of missing values for the departure time
numMissing = sum(ismissing(flights.dep_delay))
% 4. filter all the missing values from the departure delay and check the
% difference in the number of records
flights_clean = flights(~isnan(flights.dep_delay), :);
numRecordsClean = height(flights_clean);
disp("Number of records in flights = " + numRecords);
disp("Number of records in flights_clean = " + numRecordsClean);
% 5. confirm the difference in records between the two tables
diff = numRecords - numRecordsClean
% 6. Remove any departure delay greater than 2 hours (120 minutes). This
% leaves 318,798 observations.
flights_final = flights_clean(flights_clean.dep_delay <= 120, :);
height(flights_final)
% 7. Generate the following table and graph, showing the average delay per
% month.
months = unique(flights_final.Month);
res1 = table(months, zeros(size(months)), 'VariableNames', {'Month', 'AvgDelayMonth'});
for i = months(1):length(months)
month_delays = flights_final.dep_delay(flights_final.Month == i);
avg_delay_month = mean(month_delays);
res1.AvgDelayMonth(i) = avg_delay_month;
end
res1
plot(res1.Month, res1.AvgDelayMonth, '-o');
title('Average Delay by Month');
% 8. Generate the following table and graph, showing the average delay per
% hour.
hours = transpose(1:24);
res2 = table(hours, zeros(size(hours)), 'VariableNames', {'Hour', 'AvgDelayHour'});
for i = hours(1):length(hours)
hour_delays = flights_final.dep_delay(flights_final.hour == i);
avg_delay_hour = mean(hour_delays);
res2.AvgDelayHour(i) = avg_delay_hour;
end
res2 = res2(~isnan(res2.AvgDelayHour),:);
res2
plot(res2.Hour, res2.AvgDelayHour, '-o');
title('Average Delay by Hour of the Day');
% 9. Generate the following table and graph, showing the average delay by
% month and by origin
res3 = renamevars(removevars(groupsummary(flights_final,["Month","origin"],"mean","dep_delay"),'GroupCount'), 'mean_dep_delay', 'AvrDelayMonthOrigin')
jfk = res3(res3.origin == 'JFK', {'Month', 'AvrDelayMonthOrigin'});
subplot(3,1,1);
plot(jfk.Month, jfk.AvrDelayMonthOrigin, '-o');
title("JFK");
ewr = res3(res3.origin == 'EWR', {'Month', 'AvrDelayMonthOrigin'});
subplot(3,1,2);
plot(ewr.Month, ewr.AvrDelayMonthOrigin, '-o');
title("EWR");
lga = res3(res3.origin == 'LGA', {'Month', 'AvrDelayMonthOrigin'});
subplot(3,1,3);
plot(lga.Month, lga.AvrDelayMonthOrigin, '-o');
title("LGA");

View File

@ -0,0 +1,9 @@
function [grades] = clean_grades(grades)
for i = 1:(size(grades,1)*size(grades,2))
if grades(i) < 0
grades(i) = 0;
elseif grades(i) > 100
grades(i) = 0;
end
end
end

View File

@ -0,0 +1,4 @@
function [grades] = create_grades(rows, columns, min, max, seed)
rng(seed);
grades = randi([min max], rows, columns);
end

View File

@ -0,0 +1,25 @@
function [grades] = fill_estimates(grades)
for i = 1:size(grades, 2)
% making copy
copy = grades(:, i);
nonzero = 0; % count of nonzero elements to calculate avg
sum = 0; % sum of nonzero elements
% looping through copy and counting number of nonzero elements
for j = 1:size(copy,1)
if copy(j) ~= 0
nonzero = nonzero + 1;
sum = sum + copy(j);
end
end
avg = round(sum / nonzero);
% looping through original and replacing any nonzero with average
for j = 1:size(copy,1)
if grades(j,i) == 0
grades(j,i) = avg;
end
end
end
end

View File

@ -0,0 +1,4 @@
clear;
gr1 = create_grades(10,5,-10,110,100);
gr2 = clean_grades(gr1);
gr3 = fill_estimates(gr2);

View File

@ -0,0 +1,22 @@
clear;
r = 0.2; % random val for r
K = linspace(1000, 1000000, 50);
time_vec = linspace(0, 100, 50);
P = 100; % random val for P
population = zeros(length(time_vec), 50);
% implementing the model as an anonymous function
dpdt = @(t,P,r,K) r*P * (1 - (P/K));
for loopcounter = 1:50
[t,y] = ode45(dpdt, ...
time_vec, ...
P, ...
odeset, ...
r, ...
K(loopcounter));
population(:, loopcounter) = y(:,1);
end
plot(time_vec, population);

View File

@ -0,0 +1,26 @@
clear;
A = [1 2 ; 3 4 ];
B = eye(2);
% MATRIX multiplication
C = A*B;
% element-wise multiplication
D = A.* B;
rng(100);
rolls = randi([1 6], 1, 10);
% checking each element of rolls one by one to see which ones are greater than 3
gt3 = rolls > 3;
rolls(gt3); % filtering rolls to find the values > 3
A ~= 3;
% remove duplicates from rolls
unique(rolls)
for i = rolls
disp(i)
end

Binary file not shown.

View File

@ -0,0 +1,598 @@
\documentclass[11pt]{article}
\usepackage{report}
\usepackage[utf8]{inputenc} % allow utf-8 input
\usepackage[T1]{fontenc} % use 8-bit T1 fonts
\usepackage[colorlinks=true, linkcolor=black, citecolor=blue, urlcolor=blue]{hyperref} % hyperlinks
\usepackage{url} % simple URL typesetting
\usepackage{booktabs} % professional-quality tables
\usepackage{amsfonts} % blackboard math symbols
\usepackage{nicefrac} % compact symbols for 1/2, etc.
\usepackage{microtype} % microtypography
\usepackage{lipsum} % Can be removed after putting your text content
\usepackage{graphicx}
\graphicspath{ {./images/} }
\usepackage{natbib}
\usepackage{doi}
\setcitestyle{aysep={,}}
\usepackage{array}
\usepackage{listings}
\usepackage{xcolor}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codeorange}{rgb}{1,0.49,0}
\definecolor{backcolour}{rgb}{0.95,0.95,0.96}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegray},
keywordstyle=\color{codeorange},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codegreen},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2,
xleftmargin=10pt,
}
\lstset{style=mystyle}
\title{CT248 - Introduction to Modelling}
\author{Andrew Hayes\\
\AND
Student ID: 21321503\\
\AND
\AND
\AND
\AND
1BCT1\\
\AND
NUI Galway\\
}
% Uncomment to remove the date
\date{February 2022}
% Uncomment to override the `A preprint' in the header
\renewcommand{\headeright}{Introduction to Modelling}
\renewcommand{\undertitle}{Introduction to Modelling}
\renewcommand{\shorttitle}{}
%%% Add PDF metadata to help others organize their library
%%% Once the PDF is generated, you can check the metadata with
%%% $ pdfinfo template.pdf
% \hypersetup{
% pdftitle={A template for the arxiv style},
% pdfsubject={q-bio.NC, q-bio.QM},
% pdfauthor={David S.~Hippocampus, Elias D.~Striatum},
% pdfkeywords={First keyword, Second keyword, More},
% }
\begin{document}
\maketitle
\newpage
\tableofcontents
\thispagestyle{empty}
\newpage
\setcounter{page}{1}
\section{Lecture 01 - MATLAB Overview}
\textbf{MATLAB} (MAtrix LABoratory) is a powerful technical computing system for handling scientific \& engineering
calculations, designed to make \textbf{matrix computations} particularly easy.
It is a \textbf{high-level language} with an interactive development environment.
MATLAB is \textbf{loosely typed}.
MATLAB is used for:
\begin{itemize}
\item Numerical computation.
\item Data analysis \& visualisation.
\item Algorithm development \& programming.
\item Application development \& deployment.
\end{itemize}
\subsection{Variables}
A variable name in MATLAB may consist only of letters a-z, digits 0-9, and the underscore (\_) and they must start
with a letter.
A variable name may not exceed 63 characters.
MATLAB is case-sensitive, including command \& function names.
The use of a semi-colon \verb|;| at the end of a variable initialisation prevents the value from being displayed.
\verb|carSpeed = 20;|
\subsubsubsection{The MATLAB Workspace}
All variables created during a session remain in the workspace until they are \textbf{cleared}.
\begin{lstlisting}[language=MATLAB]
clear;
mph = input("Please enter the speed in mph: ");
kph = mph * 1.6;
fprintf("%d mph = %d kph\n",mph,kph);
\end{lstlisting}
The command \verb|who| lists all the names in the current workspace.
The command \verb|whos| lists the size of each variable.
Comments can be made in MATLAB using the \verb|%| sign.
\subsection{Expressions}
An \textbf{expression} is a formula consisting of variables, numbers, operators, \& function names.
Expressions are evaluated when you enter them into the MATLAB prompt.
Note that MATLAB uses the function \verb|ans| to return the last expression that was evaluated but not assigned
to a variable.
\subsubsection{Statements}
MATLAB \textbf{statements} are frequently of the form \verb|variable = expression|. \\
E.g.: \verb|s=u*t-g/2*t.^2|.
\\
This is an example of an \textbf{assignment statement}, with the value of the expression assigned to the
variable on the left-hand side.
A semicolon is at the end to suppress the output.
Statements that are too long for a line can be extended to several lines with an ellipsis of at least 3 dots \verb|...|
\\
Statements on the same line can be separated by commas or semicolons.
\newpage
\subsection{Input \& Output}
The \verb|input()| statement is used to read in input data.
\begin{lstlisting}[language=MATLAB]
name = input ("Enter your name: ");
\end{lstlisting}
The \verb|disp()| statement is used to \textbf{display} data.
The general form of the \verb|disp| statement is \verb|disp(variable)|.
\begin{lstlisting}[language=MATLAB]
>> disp("Hello World!")
>> x = 2;
>> disp(["The answer is ", num2str(x)])
The answer is 2.
>> disp([2 3 x])
2.00 3.00 2.00
\end{lstlisting}
To display more than one variable, embed the variables into an \textbf{array}.
All components of a MATLAB array must be the same type.
\begin{lstlisting}[language=MATLAB]
% Script file for converting temperatures from F to C.
% Step 1: Get the input
F = input ("Enter the temperature in degrees F: ");
% Step 2: Convert to C
C = (F -32) * 5/9;
% Step 3: Display the result
fprintf("The temperature of %f (F) is %f (C)\n",F,C);
\end{lstlisting}
\subsection{Arithmetic Operators}
The evaluation of an expression is achieved by means of arithmetic operators.
The arithmetic operations on two scalar constants / variables is shown.
Left division may seem curious, however \textit{matrix} left division has an entirely different meaning.
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
\textbf{Operation} & \textbf{Algebraic Form} & \textbf{MATLAB} \\
\hline
Addition & $ a + b $ & \verb|a + b| \\
\hline
Subtraction & $ a - b $ & \verb|a - b| \\
\hline
Multiplication & $ a \times b $ & \verb|a*b| \\
\hline
Right Division & $ a/b $ & \verb|a/b| \\
\hline
Left Division & $ b \textbackslash a $ & \verb|b\a| \\
\hline
Exponent & $ a^b $ & \verb|a^b| \\
\hline
\end{tabular}
\end{center}
MATLAB uses PEMDAS as to determine \textbf{precedence}.
\subsection{Repetition \& Loops - The For Loop}
The \verb|for| statement repeats some statement a specific number of times.
The two basic \verb|for| loop structures are as follows:
\begin{lstlisting}[language=MATLAB]
for index = j:k
statements;
end
for index = j:m:k
statements;
end
\end{lstlisting}
\verb|j:k| is a \textit{vector} with elements $j, j+1, j+2, \cdots, k$.
\verb|j:m:k| is a vector with elements $j, j+m, j+2m, \cdots$ such that the final element does not exceed $k$.
\verb|index| must be a variable. Loop statements should be indented.
\begin{lstlisting}[language=MATLAB]
for i = 1:5
disp(i);
end
\end{lstlisting}
This for loop repeats the \verb|disp()| statement 5 times, starting with \verb|i = 1| and ending with \verb| i = 5|, incrementing by 1 each iteration of the loop.
For a for loop of the form \verb|for i = a:b|, the number of iterations will be $b - a +1$.
The following example program takes in $n$ numbers and displays their average.
\begin{lstlisting}
clear;
sum = 0;
n = input("How many numbers: ");
for i=1:n
num = input("Please enter a number: ");
sum += num;
end
avg = sum/n;
fprintf("The average is %f\n.", avg);
\end{lstlisting}
\subsection{Relational Operators}
\textbf{Relational Operators} form a logical expression that is either \textit{true} or \textit{false}.
Relational operators form the basis for decision logic.
In MATLAB, "true" \& "false" can be represented both lexically (\verb|true|, \verb|false|) and logically (\verb|1|, \verb|0|).
When returning the value of a Boolean expression or variable, MATLAB will use logical true (\verb|1|) \& false (\verb|0|).
\begin{center}
\includegraphics[width=0.25\textwidth]{truefalse.png}
\end{center}
\begin{center}
\begin{tabular}{ |c|c| }
\hline
\textbf{Relational Operator} & \textbf{Meaning} \\
\hline
\verb|<| & Less than \\
\hline
\verb|<=| & Less than or equal to \\
\hline
\verb|==| & Equal to \\
\hline
\verb|~=| & Not equal to \\
\hline
\verb|>| & Greater than \\
\hline
\verb|>=| & Greater than or equal to \\
\hline
\end{tabular}
\end{center}
\subsubsection{The "If" Statement}
In MATLAB, \verb|if| statements take the general form(s):
\begin{lstlisting}[language=MATLAB]
if condition; statements; end
if condition
statements
else
statements
end
if condition
statements
elseif condition
statements
else
statements
end
\end{lstlisting}
\begin{lstlisting}[language=MATLAB]
num = input("Enter a number: ");
if num < 0; disp("Negative number"); end
\end{lstlisting}
\section{Matrices}
In linear algebra, a \textbf{matrix} is a rectangular grid of numbers arranged into \textit{rows} \& \textit{columns}.
An $r \times c$ matrix has $r$ rows \& $c$ columns.
Uppercase letters (e.g., $A$) are usually used to denote variables that are matrices.
$a_{ij}$ denotes the element in $A$ at row $i$ \& column $j$.
\begin{center}
\includegraphics[width=0.25\textwidth]{matrix.png}
\end{center}
\subsection{Multiplying a Matrix by a Scalar}
A matrix $A$ can be multiplied by a scalar $k$, resulting in a matric of the same dimensions as $A$.
The multiplication takes place in a straightforward fashion, with each element in the new matrix being the product of $k$ times the corresponding element in $A$.
\begin{center}
\includegraphics[width=0.5\textwidth]{matrixscalar.png}
\end{center}
Let matrix $C$ be the $r \times c$ product $AB$ of the $r \times n$ matrix $A$ with the $n \times c$ matrix B.
Each element of $C$, $C_{ij}$, is equal to the vector dot product of row $i$ of $A$ with column $j$ of $B$.
\begin{center}
\includegraphics[width=0.5\textwidth]{2x2example.png}
\end{center}
In MATLAB, a matrix is a rectangular object consisting of rows \& columns.
Matrices have comprehensive support with functions \& operators.
Rows can be separated when initialising a matrix using the semicolon \verb|;|.
\begin{lstlisting}
>>a = [1 2 3; 4 5 6]
a =
1 2 3
4 5 6
>>a'
ans=
1 4
2 5
3 6
\end{lstlisting}
Individual elements are usually referenced with two subscripts in the form \verb|matrixname(row, column)|.
However, elements can also be referenced using \textit{one} subscript.
In this case, MATLAB will treat the entire vector as a single column.
\begin{lstlisting}[language=MATLAB]
A=[1 2 3;4 5 6;7 8 9]
A(1,1)
A(1)
A(9)
\end{lstlisting}
Using the colon \verb|:| operator in place of a subscript denotes all the elements in the corresponding row or column.
\verb|A(3,:)| means ``all the elements in the third row''.
\verb|A(:,3)| means ``all the elements in the third column''.
You can extract subsets of a matrix using something like \verb|A(1:2, 2:3)|.
\subsubsection{Matrix Functions}
\begin{center} \begin{tabular}{ |c|c| }
\hline
\textbf{Function} & \textbf{Description} \\
\hline
\verb|eye()| & Identity Matrix \\
\hline
\verb|linspace()| & Vector with linearly spaced elements \\
\hline
\verb|ones()| & Matrix of 1s \\
\hline
\verb|rand()| & Uniformly distributed random numbers \& arrays \\
\hline
\verb|randn()| & Normally distributed random numbers \& arrays \\
\hline
\verb|zeros()| & Matrix of 0s. \\
\hline
\verb|det()| & Determinant \\
\hline
\verb|eig()| & Eigenvalues \& eigenvectors. \\
\hline
\verb|expm()| & Matrix exponential \\
\hline
\verb|inv()| & Matrix inverse \\
\hline
\verb|trace()| & Sum of diagonal elements \\
\hline
\verb|{}\| and \verb|/| & Linear equation solutions. \\
\hline
\end{tabular}
\end{center}
\subsection{Vectors}
A \textbf{vector} is a special type of matrix, having only one row or one column.
MATLAB handles matrices \& vectors in the same way.
Rules:
\begin{itemize}
\item Elements in the list must be enclose in square brackets.
\item Elements in the list must be separated by either spaces or by commas.
\end{itemize}
\begin{lstlisting}[language=MATLAB]
x = [1 2 3 4 5 6]
y = [1,2,3,4,5,6]
\end{lstlisting}
Vectors can also be initialised using the colon \verb|:| operator.
\begin{lstlisting}[language=MATLAB]
x = 1:10
y = 1:5:10
\end{lstlisting}
Operations can be performed on vectors, e.g \verb|sum(x)|, \verb|mean(x)|, etc.
Elements in a vector can be accessed via \verb|x(1)| or \verb|x(1:3)| to get a range of elements.
Note: vectors in MATLAB are indexed from 1, not 0.
\subsubsection{Transposing Vectors}
The vectors generated thus far have been \textit{row vectors}.
\textit{Column vectors} may be needed for matrix operations.
The single quote \verb|'| can be used to transpose a vector.
\begin{center}
\includegraphics[width=0.25\textwidth]{singlequote.png}
\end{center}
\section{Lecture 02 - Logical Vectors \& Arrays}
\subsection{Element-Wise Operations}
\section{MATLAB Functions}
MATLAB allows you to create your own function \textbf{M-files}.
A function file differs from a script file in that the function M-file communicates with the MATLAB workspace through
specially designated input \& output arguments.
A function M-file \verb|name.m| has the following general form:
\begin{lstlisting}[language=MATLAB]
function [outarg1, outarg2, ...] = name(inarg1, inarg2, ...)
% help text
outarg1 = ...;
outarg2 = ...;
end
\end{lstlisting}
\begin{itemize}
\item \textbf{Function Keyword -} The function file must start with the keyword \verb|function|.
\item \textbf{Input \& Output Arguments -} The input \& output arguments define the function's means of communication with the workspace.
\begin{itemize}
\item If there is more than one output argument, the output arguments must be separated by commas \& enclosed in square brackets.
\item Input \& output variables can be vectors.
\end{itemize}
\item \textbf{Help Text -} When you type \verb|help function_name|, MATLAB displays the comment lines that appear between the function definition \& the first non-comment line.
\item Function names should follow the MATLAB rules for variable names.
\end{itemize}
If a function changes the value of any of its input arguments, the change is \textbf{not} reflected in the actual argument.
An input argument is only passed by value if a function modifies it.
If a function does not modify an input argument, it is passed by reference.
A variable number of arguments can be passed to a function.
A function may be called with all, some, or none of its arguments.
The same applies to output arguments.
\verb|nargin| displays the number of arguments passed.
\subsection{Scope}
Any \textbf{local variables} defined inside a function are not accessible outside the function.
These local variables exist only inside the function, which has its own workspace, separate from the base workspace.
Variables which are defined in the base workspace and are not normally accessible inside functions.
If functions (\& possibly the base workspace) declare variables as \textbf{global}. then they will all share a single copy of those variables.
\textbf{Persistent variables}, unlike local variables, remain persistent between function calls.
A persistent variable is initially an empty array.
Persistent variables can be declared with the keyword \verb|persistent <variablename>|.
\subsection{Subfunctions}
The function M-file may contain code for more than one function.
The first function in the M-file is called the \textbf{primary function}.
Additional functions are known as \textbf{subfunctions}, and are visible only to the primary functions \& to the other subfunctions.
Subfunctions follow each other ina ny order \textit{after} the primary function.
\section{Processing Images in MATLAB}
\subsection{Examples of Image Types}
\begin{itemize}
\item \textbf{Binary Images:} 2D arrays that assign one numerical value from the set (0,1) to each pixel in the image.
Often called \textbf{logical images}.
\verb|0| corresponds to black, while \verb|1| corresponds to white.
Binary images can be represented as a simple bit stream.
\item \textbf{Intensity/Grayscale Images:} 2D arrays that assign one numerical value to each pixel, representing the intensity
at said pixel.
The range is bounded by the bit resolution of the image.
\item \textbf{RGB Images:} 3D arrays that assign three numerical values to each pixel, with each value corresponding to the red,
green, \& blue image channel.
Pixels are accessed by \verb|I(Row,Column,Channel)| in MATLAB.
\end{itemize}
\subsection{Key MATLAB Functions}
MATLAB's image processing toolbox contains an extensive image processing library, including:
\begin{itemize}
\item \verb|imread(filename)| - Reads an image from a graphical file and converts it to a MATLAB array object.
\item \verb|imshow(object)| - Displays an image.
\item \verb|linspace(X1,X2,N)| - Generates a row vector of \verb|N| linearly spaced points between \verb|X1| \& \verb|X2|.
If \verb|N| is excluded, 100 points will be generated.
\item \verb|subplot(m,n,p)| - Creates axes in tiled positions by dividing the current figure into an \verb|m|-by-\verb|n|
grid and creating axes in the position specified by \verb|p|.
MATLAB numbers subplot positions by row.
The first subplot is the first column of the first row, the second subplot is the second column
of the second row, etc.
\end{itemize}
\subsection{Image Colour}
An image contains one or more colour channels that define the intensity or colour at a particular pixel location \verb|I(m.n)|.
In the simplest case, each pixel location contains only a single numerical value representing the signal level at that point in the image.
The most common colour map is \textbf{greyscale}.
The maximum numerical value representing the signal level is $2^8-2=255$.
\subsection{Operations on Pixels}
The most basic type of image processing is a \textbf{point transform} which maps the value at individual points (pixels) in the input
image to corresponding points in an output image.
In a mathematical sense, it's a one-to=one functional mapping from input to output.
Types of operations include:
\begin{itemize}
\item Pixel addition \& subtraction.
\item Thresholding.
\item RGB to Greyscale.
\item Rotation (90º).
\item Simple cropping.
\end{itemize}
\subsubsection{Arithmetic Operations on Images}
Arithmetic operations can be performed quickly and easily on images.
The example below shows contrast adjustment.
\begin{lstlisting}[language=MATLAB]
I = imread("cameraman.tif");
O = I + 50;
O1 = I + 100;
O2 = I - 100;
subplot(2,2,1),imshow(I),title("Original Image");
subplot(2,2,2),imshow(O),title("+50");
subplot(2,2,3),imshow(O1),title("+100");
subplot(2,2,4),imshow(O2),title("-100");
\end{lstlisting}
\begin{center}
\includegraphics[width=0.7\textwidth]{arithmeticoperationsonimages.png}
\end{center}
\subsubsection{Thresholding}
\textbf{Thresholding} produces a binary image from a greyscale or colour image by setting pixels to \verb|1| or \verb|0| depending on
whether they are above or below the threshold value.
This is useful to help separate the image foreground from the background.
Logical operators are very useful for this.
\begin{lstlisting}[language=MATLAB]
I = imread('rice.png');
T1 = I > 100;
T2 = I > 105;
T3 = I > 110;
T4 = I > 115;
T5 = I > 120;
subplot(2,3,1),imshow(I),title('Original Image');
subplot(2,3,2),imshow(T1),title('Threshold @100');
subplot(2,3,3),imshow(T2),title('Threshold @105');
subplot(2,3,4),imshow(T3),title('Threshold @110');
subplot(2,3,5),imshow(T4),title('Threshold @115');
subplot(2,3,6),imshow(T5),title('Threshold @120');
\end{lstlisting}
\section{Data Science}
\subsection{Introducing the Table in MATLAB}
\textbf{Tables} are used to collect heterogeneous data \& metadata in a single container.
Tables are suitable for storing column-oriented or tabular data that is often stored as columns in a text file or in a spreadsheet.
Tables can accomodate variables of different types, sizes, units, etc.
Tables are often used to store experimental data, with rows representing the different observations and columns representing different measured variables.
Tables can be subscripted using parentheses much like ordinary numeric arrays, but in addition to numeric and logical indices, one can use a table's variable and row names (if defined) as \textbf{indices}.
One can access individual variables in a table much like fields in a structure, using \textbf{dot subscripting}.
One can access the contents of one or more variables using \textbf{brace subscripting}.
\bibliographystyle{unsrtnat}
\bibliography{references}
\end{document}

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@ -0,0 +1,264 @@
\NeedsTeXFormat{LaTeX2e}
\ProcessOptions\relax
% fonts
\renewcommand{\rmdefault}{ptm}
\renewcommand{\sfdefault}{phv}
% set page geometry
\usepackage[verbose=true,letterpaper]{geometry}
\AtBeginDocument{
\newgeometry{
textheight=9in,
textwidth=6.5in,
top=1in,
headheight=14pt,
headsep=25pt,
footskip=30pt
}
}
\widowpenalty=10000
\clubpenalty=10000
\flushbottom
\sloppy
\newcommand{\headeright}{Ph.D. Confirmation Report}
\newcommand{\undertitle}{Ph.D. Confirmation Report}
\newcommand{\shorttitle}{\@title}
\usepackage{fancyhdr}
\fancyhf{}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.4pt}
\fancyheadoffset{0pt}
\rhead{\scshape \footnotesize \headeright}
\chead{\shorttitle}
\cfoot{\thepage}
%Handling Keywords
\def\keywordname{{\bfseries \emph{Keywords}}}%
\def\keywords#1{\par\addvspace\medskipamount{\rightskip=0pt plus1cm
\def\and{\ifhmode\unskip\nobreak\fi\ $\cdot$
}\noindent\keywordname\enspace\ignorespaces#1\par}}
% font sizes with reduced leading
\renewcommand{\normalsize}{%
\@setfontsize\normalsize\@xipt\@xiipt
\abovedisplayskip 7\p@ \@plus 2\p@ \@minus 5\p@
\abovedisplayshortskip \z@ \@plus 3\p@
\belowdisplayskip \abovedisplayskip
\belowdisplayshortskip 4\p@ \@plus 3\p@ \@minus 3\p@
}
\normalsize
\renewcommand{\small}{%
\@setfontsize\small\@xpt\@xipt
\abovedisplayskip 6\p@ \@plus 1.5\p@ \@minus 4\p@
\abovedisplayshortskip \z@ \@plus 2\p@
\belowdisplayskip \abovedisplayskip
\belowdisplayshortskip 3\p@ \@plus 2\p@ \@minus 2\p@
}
\renewcommand{\footnotesize}{\@setfontsize\footnotesize\@ixpt\@xpt}
\renewcommand{\scriptsize}{\@setfontsize\scriptsize\@viipt\@viiipt}
\renewcommand{\tiny}{\@setfontsize\tiny\@vipt\@viipt}
\renewcommand{\large}{\@setfontsize\large\@xiipt{14}}
\renewcommand{\Large}{\@setfontsize\Large\@xivpt{16}}
\renewcommand{\LARGE}{\@setfontsize\LARGE\@xviipt{20}}
\renewcommand{\huge}{\@setfontsize\huge\@xxpt{23}}
\renewcommand{\Huge}{\@setfontsize\Huge\@xxvpt{28}}
% sections with less space
\providecommand{\section}{}
\renewcommand{\section}{%
\@startsection{section}{1}{\z@}%
{-2.0ex \@plus -0.5ex \@minus -0.2ex}%
{ 1.5ex \@plus 0.3ex \@minus 0.2ex}%
{\large\bf\raggedright}%
}
\providecommand{\subsection}{}
\renewcommand{\subsection}{%
\@startsection{subsection}{2}{\z@}%
{-1.8ex \@plus -0.5ex \@minus -0.2ex}%
{ 0.8ex \@plus 0.2ex}%
{\normalsize\bf\raggedright}%
}
\providecommand{\subsubsection}{}
\renewcommand{\subsubsection}{%
\@startsection{subsubsection}{3}{\z@}%
{-1.5ex \@plus -0.5ex \@minus -0.2ex}%
{ 0.5ex \@plus 0.2ex}%
{\normalsize\bf\raggedright}%
}
\providecommand{\paragraph}{}
\renewcommand{\paragraph}{%
\@startsection{paragraph}{4}{\z@}%
{1.5ex \@plus 0.5ex \@minus 0.2ex}%
{-1em}%
{\normalsize\bf}%
}
\providecommand{\subparagraph}{}
\renewcommand{\subparagraph}{%
\@startsection{subparagraph}{5}{\z@}%
{1.5ex \@plus 0.5ex \@minus 0.2ex}%
{-1em}%
{\normalsize\bf}%
}
\providecommand{\subsubsubsection}{}
\renewcommand{\subsubsubsection}{%
\vskip5pt{\noindent\normalsize\rm\raggedright}%
}
% float placement
\renewcommand{\topfraction }{0.85}
\renewcommand{\bottomfraction }{0.4}
\renewcommand{\textfraction }{0.1}
\renewcommand{\floatpagefraction}{0.7}
\newlength{\@abovecaptionskip}\setlength{\@abovecaptionskip}{7\p@}
\newlength{\@belowcaptionskip}\setlength{\@belowcaptionskip}{\z@}
\setlength{\abovecaptionskip}{\@abovecaptionskip}
\setlength{\belowcaptionskip}{\@belowcaptionskip}
% swap above/below caption skip lengths for tables
\renewenvironment{table}
{\setlength{\abovecaptionskip}{\@belowcaptionskip}%
\setlength{\belowcaptionskip}{\@abovecaptionskip}%
\@float{table}}
{\end@float}
% footnote formatting
\setlength{\footnotesep }{6.65\p@}
\setlength{\skip\footins}{9\p@ \@plus 4\p@ \@minus 2\p@}
\renewcommand{\footnoterule}{\kern-3\p@ \hrule width 12pc \kern 2.6\p@}
\setcounter{footnote}{0}
% paragraph formatting
\setlength{\parindent}{\z@}
\setlength{\parskip }{5.5\p@}
% list formatting
\setlength{\topsep }{4\p@ \@plus 1\p@ \@minus 2\p@}
\setlength{\partopsep }{1\p@ \@plus 0.5\p@ \@minus 0.5\p@}
\setlength{\itemsep }{2\p@ \@plus 1\p@ \@minus 0.5\p@}
\setlength{\parsep }{2\p@ \@plus 1\p@ \@minus 0.5\p@}
\setlength{\leftmargin }{3pc}
\setlength{\leftmargini }{\leftmargin}
\setlength{\leftmarginii }{2em}
\setlength{\leftmarginiii}{1.5em}
\setlength{\leftmarginiv }{1.0em}
\setlength{\leftmarginv }{0.5em}
\def\@listi {\leftmargin\leftmargini}
\def\@listii {\leftmargin\leftmarginii
\labelwidth\leftmarginii
\advance\labelwidth-\labelsep
\topsep 2\p@ \@plus 1\p@ \@minus 0.5\p@
\parsep 1\p@ \@plus 0.5\p@ \@minus 0.5\p@
\itemsep \parsep}
\def\@listiii{\leftmargin\leftmarginiii
\labelwidth\leftmarginiii
\advance\labelwidth-\labelsep
\topsep 1\p@ \@plus 0.5\p@ \@minus 0.5\p@
\parsep \z@
\partopsep 0.5\p@ \@plus 0\p@ \@minus 0.5\p@
\itemsep \topsep}
\def\@listiv {\leftmargin\leftmarginiv
\labelwidth\leftmarginiv
\advance\labelwidth-\labelsep}
\def\@listv {\leftmargin\leftmarginv
\labelwidth\leftmarginv
\advance\labelwidth-\labelsep}
\def\@listvi {\leftmargin\leftmarginvi
\labelwidth\leftmarginvi
\advance\labelwidth-\labelsep}
% create title
\providecommand{\maketitle}{}
\renewcommand{\maketitle}{%
\par
\begingroup
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
% for perfect author name centering
\renewcommand{\@makefnmark}{\hbox to \z@{$^{\@thefnmark}$\hss}}
% The footnote-mark was overlapping the footnote-text,
% added the following to fix this problem (MK)
\long\def\@makefntext##1{%
\parindent 1em\noindent
\hbox to 1.8em{\hss $\m@th ^{\@thefnmark}$}##1
}
\thispagestyle{empty}
\@maketitle
\@thanks
%\@notice
\endgroup
\let\maketitle\relax
\let\thanks\relax
}
% rules for title box at top of first page
\newcommand{\@toptitlebar}{
\hrule height 2\p@
\vskip 0.25in
\vskip -\parskip%
}
\newcommand{\@bottomtitlebar}{
\vskip 0.29in
\vskip -\parskip
\hrule height 2\p@
\vskip 0.09in%
}
% create title (includes both anonymized and non-anonymized versions)
\providecommand{\@maketitle}{}
\renewcommand{\@maketitle}{%
\vbox{%
\hsize\textwidth
\linewidth\hsize
\vskip 0.8in
\@toptitlebar
\centering
{\LARGE\sc \@title\par}
\@bottomtitlebar
\vskip 0.5in
\textsc{\Large\undertitle}\\
\vskip 2.0in
\def\And{%
\end{tabular}\hfil\linebreak[0]\hfil%
\begin{tabular}[t]{c}\bf\rule{\z@}{24\p@}\ignorespaces%
}
\def\AND{%
\end{tabular}\hfil\linebreak[4]\hfil%
\begin{tabular}[t]{c}\bf\rule{\z@}{24\p@}\large\ignorespaces%
}
\begin{tabular}[t]{c}\bf\rule{\z@}{24\p@}\Large\@author\end{tabular}%
\vskip 1.0in \@minus 0.1in \center{\large\@date} \vskip 0.2in
}
}
% add conference notice to bottom of first page
\newcommand{\ftype@noticebox}{8}
\newcommand{\@notice}{%
% give a bit of extra room back to authors on first page
\enlargethispage{2\baselineskip}%
\@float{noticebox}[b]%
\footnotesize\@noticestring%
\end@float%
}
% abstract styling
\renewenvironment{abstract}
{
\centerline
{\large \bfseries \scshape Abstract}
\begin{quote}
}
{
\end{quote}
}
\endinput

Binary file not shown.