[programming] add advanced data type box
This commit is contained in:
parent
902cf9f260
commit
6e9a30f679
@ -1009,6 +1009,60 @@ segment of data of a certain time span (the stimulus was on,
|
||||
\end{itemize}
|
||||
\end{exercise}
|
||||
|
||||
\begin{ibox}[ht]{\label{whenscriptsbox}Advanced data types}
|
||||
Thoughout this script and the exercises we will limit ourselves to
|
||||
the basic data types introduced above (int, double, char, scalars,
|
||||
vectors, matrices and strings). There are, however, \matlab{}-
|
||||
specific advanced data structures that make life easier (mostly). We
|
||||
will introduce them breifly here and refer to the \matlab{} help for
|
||||
further information. \textbf{Note: Some of these data types are
|
||||
more recent additions to the matlab language. One should consider
|
||||
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
|
||||
and thus can build a trees. Structures are often used to combine
|
||||
data and mtadata 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 arrays} requires a special
|
||||
operator the \code{\{\}}. \matlab{} uses \codeterm{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 braces that are used to
|
||||
create the array and are also used for indexing.
|
||||
|
||||
\textbf{Tables} Tabular structure that allows to have columns of
|
||||
varying type 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
|
||||
variables (one storing the time, the other the measurement) would be
|
||||
required. \codeterm{Timetables} offer specific convenience functions
|
||||
to work with timestamps.
|
||||
|
||||
\textbf{Maps} In a \codeterm{map} a \codeterm{value} is associated
|
||||
with an arbitrary \codeterm{key}. The \codeterm{key} is not
|
||||
restricted to be an integer but can be almost anything. Maps are an
|
||||
alternative to structures with the additional advantage that the key
|
||||
can be used during indexing: \varcode{my\_map('key')}.
|
||||
|
||||
\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}.
|
||||
\begin{lstlisting}[caption={Using Categorical arrays}, label=categoricallisting]
|
||||
>> months = categorical({'Jan', 'Feb', 'Jan', 'Dec'});
|
||||
>> events = [10, 2, 18, 20 ];
|
||||
>> events(months == 'Jan')
|
||||
ans =
|
||||
10 18
|
||||
\end{lstlisting}
|
||||
|
||||
\end{ibox}
|
||||
|
||||
\section{Control flow}\label{controlstructsec}
|
||||
|
||||
|
Reference in New Issue
Block a user