From b67ceae7811ce8e121d84ec10c39599c75ee295c Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Mon, 9 Nov 2020 22:03:14 +0100 Subject: [PATCH] [programming] add box about colon operator --- header.tex | 2 +- programming/lecture/programming.tex | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/header.tex b/header.tex index 6511f0a..29f6ba8 100644 --- a/header.tex +++ b/header.tex @@ -5,7 +5,7 @@ \author{{\LARGE Jan Grewe \& Jan Benda}\\[5ex]Abteilung Neuroethologie\\[2ex]% \includegraphics[width=0.3\textwidth]{UT_WBMW_Rot_RGB}\vspace{3ex}} -\date{WS 2019/2020\\\vfill% +\date{WS 2020/2021\\\vfill% \centerline{\includegraphics[width=0.7\textwidth]{announcements/correlationcartoon}% \rotatebox{90}{\footnotesize\url{www.xkcd.com}}}} diff --git a/programming/lecture/programming.tex b/programming/lecture/programming.tex index 80eb762..e05e381 100644 --- a/programming/lecture/programming.tex +++ b/programming/lecture/programming.tex @@ -190,8 +190,8 @@ represented (table~\ref{dtypestab}). Data type & memory demand & range & example \erh \\ \hline \code{single} & 32 bit & $\approx -3.4^{38}$ to $\approx 3.4^{38}$ & Floating point numbers.\erb \\ \code{double} & 64 bit & $\approx -10^{308}$ to $\approx 10^{308}$ & - Floating point numbers.\erb\\ \code{int} & 64 bit & $-2^{31}$ - to $2^{31}-1$ & Integer values. \\ \code{int16} & 16 bit & + Floating point numbers.\erb\\ \code{int} & 64 bit & $-2^{63}$ + to $2^{63}-1$ & Integer values. \\ \code{int16} & 16 bit & $-2^{15}$ to $2^{15}-1$ & Digitizes measurements. \\ \code{uint8} & 8 bit & $0$ bis $255$ & Digitized intensities of colors in images. \\ \hline @@ -402,6 +402,17 @@ ans = could you find out the size of the \varcode{a} in the 2nd dimension? \end{exercise} +\begin{important}[The : (colon) operator] + The colon \code[Operator!colon@:]{:} operator is often used when working with vectors. It has multiple purposes. + \begin{enumerate} + \item In the simplest form, \code{x = a:b} with \code{a} and \code{b} being two numbers, it creates + a vector \code{x} containing the numbers \code{a} to \code{b} in integer steps. In \matlab{} the borders $a$ and $b$ are included $[a, b]$ or $a\leq x \leq b$. + \item In the form \code{x = a:c:b} the vector \code{x} uses a \emph{stepsize} of \code{c} to create the range of numbers. + \item When used in the context of indexing such as \code{x(:)} all elements of the vector x are accessed. + \item As vectors are often used for indexing in other vectors one use the colon operator to create such vectors implicitely, e.g. \varcode{x(1:2:end)} to access every seond element of \code{x}. + \end{enumerate} +\end{important} + \subsubsection{Operations on vectors} Similarly to the scalar variables discussed above we can work with