removed \codeterm (replaced by \entermde)

This commit is contained in:
2019-12-10 09:14:10 +01:00
parent c063cc9f0e
commit 39a1e51bc4
4 changed files with 100 additions and 99 deletions

View File

@@ -76,13 +76,15 @@ z =
Line 1 can be read like: ``Create a variable with the name \varcode{x}
and assign the value 38''. The equality sign is the so called
\codeterm[Operator!assignment]{assignment operator}. Line 5 defines a variable \varcode{y}
and assigns an empty value. If not explicitly specified \matlab{}
variables will have the \codeterm{double} (a numeric data type, see
below) data type. In line 9, however, we create a variable \varcode{z}
and assign the character ``A'' to it. Accordingly, \varcode{z} does
not have the numeric \codeterm{double} data type but is of the type
\codeterm{character}. \textbf{Note:} \matlab{} uses single quotes for characters or strings of characters.
\entermde[Operator!assignment]{Operator!Zuweisungs@Zuweisungs\texttildelow}{assignment
operator}. Line 5 defines a variable \varcode{y} and assigns an
empty value. If not explicitly specified \matlab{} variables will have
the \code{double} (a numeric data type, see below) data type. In
line 9, however, we create a variable \varcode{z} and assign the
character ``A'' to it. Accordingly, \varcode{z} does not have the
numeric \code{double} data type but is a
\enterm{character} type. \textbf{Note:} \matlab{} uses single quotes for
both characters or strings of characters.
There are two ways to find out the actual data type of a variable: the
\code{class()} and the \code{whos} functions. While \code{class()}
@@ -121,7 +123,7 @@ x y z
\pagebreak[4]
\subsection{Working with variables}
We can certainly work, i.e. do calculations, with variables. \matlab{}
knows all basic \codeterm[Operator!arithmetic]{arithmetic operators}
knows all basic \entermde[Operator!arithmetic]{Operator!arithmetischer}{arithmetic operators}
such as \code[Operator!arithmetic!1add@+]{+},
\code[Operator!arithmetic!2sub@-]{-},
\code[Operator!arithmetic!3mul@*]{*} and
@@ -164,17 +166,17 @@ their values. Whenever the value of a variable should change, the
As mentioned above, the data type associated with a variable defines how the stored bit pattern is interpreted. The major data types are:
\begin{itemize}
\item \codeterm{integer}: Integer numbers. There are several subtypes
\item \enterm{integer}: Integer numbers. There are several subtypes
which, for most use-cases, can be ignored when working in \matlab{}.
\item \codeterm{single} \codeterm{double}: Floating point numbers. In
\item \enterm{single} \enterm{double}: Floating point numbers. In
contrast to the real numbers that are represented with this data
type the number of numeric values that can be represented is limited
(countable).
\item \codeterm{complex}: Complex numbers having a real and imaginary
\item \enterm{complex}: Complex numbers having a real and imaginary
part.
\item \codeterm{logical}: Boolean values that can be evaluated to
\item \enterm{logical}: Boolean values that can be evaluated to
\code{true} or \code{false}.
\item \codeterm{char}: ASCII characters.
\item \enterm{character}: ASCII characters.
\end{itemize}
There is a variety of numeric data types that require different
amounts of memory and have different ranges of values that can be
@@ -196,7 +198,7 @@ represented (table~\ref{dtypestab}).
\end{tabular}
\end{table}
By default \matlab{} uses the \codeterm{double} data type whenever
By default \matlab{} uses the \enterm{double} data type whenever
numerical values are stored. Nevertheless, there are use-cases
in which different data types are better suited. Box~\ref{daqbox}
exemplifies one of such cases.
@@ -229,7 +231,7 @@ exemplifies one of such cases.
In this context it is most efficient to store the measured values as
\code{int16} instead of \code{double} numbers. Storing floating
point numbers requires four times more memory (8 instead of 2
\codeterm{Byte}, 64 instead of 16 bit) and offers no additional
bytes, 64 instead of 16 bit) and offers no additional
information.
\end{ibox}
@@ -338,8 +340,8 @@ ans =
The content of a vector is accessed using the element's index
(figure~\ref{vectorindexingfig}). Each element has an individual
\codeterm{index} that ranges (int \matlab{}) from 1 to the number of
elements irrespective of the type of vector.
\entermde{Index}{index} that ranges (int \matlab{}) from 1 to the
number of elements irrespective of the type of vector.
\begin{figure}[ht]
\includegraphics[width=0.4\columnwidth]{arrayIndexing}
@@ -350,7 +352,7 @@ elements irrespective of the type of vector.
\begin{important}[Indexing]
Elements of a vector are accessed via their index. This process is
called \codeterm{indexing}.
called \entermde{Indizierung}{indexing}.
In \matlab{} the first element has the index one.
@@ -651,7 +653,7 @@ elements of a matrix by it's index. Similar to a coordinate system
each element is addressed using an n-tuple with $n$ the number of
dimensions (figure~\ref{matrixindexingfig},
listing~\ref{matrixIndexing}). This type of indexing is called
\codeterm{subscript indexing}. The first coordinate refers always to
\enterm[indexing!subscript]{subscript indexing}. The first coordinate refers always to
the row, the second to the column, the third to the page, and so on.
\begin{lstlisting}[caption={Accessing elements in matrices, indexing.}, label=matrixIndexing]
@@ -835,9 +837,9 @@ values (\varcode{true} or \varcode{false}). This implies that we need
only a single bit to store this information as 0 (false) or 1 (true)
It would be a waste of space to use more than one bit for
it. Accordingly, \matlab{} knows a special data type
(\codeterm{logical}) to store such information efficiently. \matlab{}
(\enterm{logical}) to store such information efficiently. \matlab{}
also knows the keywords \code{true} and \code{false} which are
synonymous for the \codeterm{logical} values 1 and
synonymous for the logical values 1 and
0. Listing~\ref{logicaldatatype} exemplifies the use of the logical
data type.
@@ -884,10 +886,11 @@ table~\ref{logicaloperators}) which are introduced in the following
sections.
\subsection{Relational operators}
With \codeterm[Operator!relational]{relational operators}
(table~\ref{relationaloperators}) we can ask questions such as: ''Is
the value of variable \varcode{a} larger than the value of
\varcode{b}?'' or ``Is the value in \varcode{a} equal to the one
With
\entermde[Operator!relational]{Operator!Vergleichs@Vergleichs\texttildelow}{relational
operators} (table~\ref{relationaloperators}) we can ask questions
such as: ''Is the value of variable \varcode{a} larger than the value
of \varcode{b}?'' or ``Is the value in \varcode{a} equal to the one
stored in variable \varcode{b}?''.
\begin{table}[h!]
@@ -943,7 +946,7 @@ number is greater than a certain threshold (\varcode{x > 0.25}). But what
if we wanted to check whether the number falls into the range greater
than 0.25 but less than 0.75? Numbers that fall into this range must
satisfy the one and the other condition. With
\codeterm[Operator!logical]{logical
\entermde[Operator!logical]{Operator!logischer}{logical
operators} (table~\ref{logicaloperators}) single Boolean expressions
can be joined to form more complex Boolean operations.
@@ -1071,7 +1074,7 @@ values stored in a vector or matrix. It is very powerful and, once
understood, very intuitive.
The basic concept is that applying a Boolean operation on a vector
results in a \codeterm{logical} vector of the same size (see
results in a \enterm{logical} vector of the same size (see
listing~\ref{logicaldatatype}). This logical vector is then used to
select only those values for which the logical vector is true. Line 14
in listing~\ref{logicalindexing1} can be read: ``Select all those
@@ -1152,14 +1155,14 @@ segment of data of a certain time span (the stimulus was on,
this if downward compatibility is desired/needed.}
\textbf{Structures} Arrays of named fields that each can contain
arbitrary data types. \codeterm{Structures} can have sub-structures
arbitrary data types. \enterm{Structures} can have sub-structures
and thus can build a trees. Structures are often used to combine
data and metadata in a single variable.
\textbf{Cell arrays} Arrays of variables that contain different
types. Unlike structures, the entries of a \codeterm{cell array} are
not named. Indexing in \codeterm[cell array]{cell arrays} requires a
special operator the \code{\{\}}. \matlab{} uses \codeterm[cell
types. Unlike structures, the entries of a \enterm{cell array} are
not named. Indexing in \enterm[cell array]{cell arrays} requires a
special operator the \code{\{\}}. \matlab{} uses \enterm[cell
array]{cell arrays} for example when strings of different lengths
should be stored in the same variable: \varcode{months = \{'Januar',
'February', 'March', 'April', 'May', 'Jun'\};}. Note the curly
@@ -1167,14 +1170,14 @@ segment of data of a certain time span (the stimulus was on,
indexing.
\textbf{Tables} Tabular structure that allows to have columns of
varying type combined with a header (much like a spreadsheet).
different types combined with a header (much like a spreadsheet).
\textbf{Timetables} Array of values that are associated with a
timestamp. For example one can store measurements, that are made in
irregular intervals togehter with the measurement time in a single
variable. Without the \codeterm{Timetable} data type at least two
variable. Without the \enterm{Timetable} data type at least two
variables (one storing the time, the other the measurement) would be
required. \codeterm[Timetable]{Timetables} offer specific
required. \enterm[Timetable]{Timetables} offer specific
convenience functions to work with timestamps.
\textbf{Maps} In a \code{containers.Map} a \entermde{Wert}{value} is
@@ -1185,8 +1188,8 @@ segment of data of a certain time span (the stimulus was on,
\textbf{Categorical arrays} are used to stored values that come from
a limited set of values, e.g. Months. Such categories can then be
used for filter operations. \codeterm{Categorical arrays} are often
used in conjunctions with \codeterm{Tables}.
used for filter operations. \enterm{Categorical arrays} are often
used in conjunctions with \enterm{Tables}.
\begin{lstlisting}[caption={Using Categorical arrays}, label=categoricallisting]
>> months = categorical({'Jan', 'Feb', 'Jan', 'Dec'});
>> events = [10, 2, 18, 20 ];
@@ -1495,22 +1498,22 @@ and executed line-by-line from top to bottom.
\item \entermde[Object]{Objekte}{Objects} (not covered here)
\end{enumerate}
Programs are stored in so called \codeterm[m-file]{m-files}
Programs are stored in so called \entermde[m-file]{m-File}{m-files}
(e.g. \file{myProgram.m}). To use them they have to be \emph{called}
from the command line or from within another program. Storing your code in
programs increases the re-usability. So far we have used
from the command line or from within another program. Storing your
code in programs increases the re-usability. So far we have used
\emph{scripts} to store the solutions of the exercises. Any variable
that was created appeared in the \codeterm{workspace} and existed even
after the program was finished. This is very convenient but also bears
some risks. Consider the case that \file{script\_a.m} creates a
certain variable and assigns a value to it for later use. Now it calls
a second program (\file{script\_b.m}) that, by accident, uses the same
variable name and assigns a different value to it. When
\file{script\_b.m} is done, the control returns to \file{script\_a.m}
and if it now wants to read the previously stored variable, it will
contain a different value than expected. Bugs like this are hard to
find since each of the programs alone is perfectly fine and works as
intended. A solution for this problem are the
that was created appeared in the \entermde{Arbeitsbereich}{workspace}
and existed even after the program was finished. This is very
convenient but also bears some risks. Consider the case that
\file{script\_a.m} creates a certain variable and assigns a value to
it for later use. Now it calls a second program (\file{script\_b.m})
that, by accident, uses the same variable name and assigns a different
value to it. When \file{script\_b.m} is done, the control returns to
\file{script\_a.m} and if it now wants to read the previously stored
variable, it will contain a different value than expected. Bugs like
this are hard to find since each of the programs alone is perfectly
fine and works as intended. A solution for this problem are the
\entermde[function]{Funktion}{functions}.
\subsection{Functions}
@@ -1533,8 +1536,9 @@ argument(s). The function head is then followed by the function's
body. A function is ended by and \code{end} (this is in fact optional
but we will stick to this). Each function that should be directly used
by the user (or called from other programs) should reside in an
individual \codeterm{m-file} that has the same name as the function. By
using functions instead of scripts we gain several advantages:
individual \entermde{m-File}{m-file} that has the same name as the
function. By using functions instead of scripts we gain several
advantages:
\begin{itemize}
\item Encapsulation of program code that solves a certain task. It can
be easily re-used in other programs.