Kontakt
Contact
Prof. Dr. Jutta Kretzberg
Tel.: +49-(0)441-798-3314
E-Mail:
Office: W4-0-078
Matlab - Terms
Important concepts in Matlab:
Matrix:
Matlab is structured in such a way that almost all data is displayed in the form of matrices (i.e. in tabular form). In principle, matrices can have any number of dimensions. In a two-dimensional matrix, the first index denotes the row, the second the column, e.g.
m₁₁ m₁₂ m₁₃
m₂₁ m₂₂₂ m₂₃
m₁₁ etc are referred to as entries or components of the matrix.
Vector:
A vector is a special case of a matrix that has either only one row and any number of columns (row vector) or only one column and any number of rows (column vector).
Variable:
An identifier for a content, e.g. for a number, a vector or a character string. In Matlab, variable names consist of letters, numbers and underscores, but must always begin with a letter.
Command:
A command is the name of a programme. Matlab comes with a large number of commands that can be used. Behind each of these is a programme, many of which can be viewed as m-files (but not all of them - Matlab doesn't want to be seen to be overselling itself). If you write m-files yourself, you can then use them just like the built-in commands in Matlab. (But be careful: the commands for self-written programmes can only be called in the directory in which they are saved).
Syntax:
The exact way in which you get Matlab to execute a command is called syntax. If you make a mistake or mistype and the syntax is not adhered to (e.g. an open bracket is not closed again), there is a syntax error, which Matlab indicates with a red error message.
Command line:
The command line is used to control the execution of commands in Matlab. If the >> sign is visible in the large input window and the cursor is flashing behind it, Matlab is ready for input. While a programme is being executed, "busy" is displayed at the bottom and no cursor is visible.
Algorithm:
An algorithm is a linear sequence of operations that take place one after the other. An algorithm is initially independent of the programming language; it can be converted (implemented) into programmes in different languages.
Implementation:
Algorithms are implemented by converting them into sequences of commands in a programming language. The end product of the implementation is the finished programme.
Programme:
The conversion of an algorithm into a sequence of commands in a programming language. Calling the programme name causes the programme to be executed.
Workspace:
The workspace contains all variables that can be accessed from the command line. These can be viewed in the top left-hand window. To be able to process data, you must first get it into the workspace, e.g. load it from a file or type it in.
Script:
A script is a programme without input and output parameters. The execution of a script corresponds exactly to a sequence of commands that are typed into the programme line of the workspace one after the other and executed. The only difference is that this sequence can be repeated more conveniently by typing a single command (the script name). Accordingly, all variables contained in the script are also variables of the workspace and vice versa.
Encapsulation:
Often you do not want the variables of the workspace to be changed by executing a programme. In this case, so-called encapsulation is used in a function that has its own variables and an individual life separate from the workspace.
Input and output parameters:
Data can be exchanged between the workspace and functions using input and output parameters. Input parameters transfer values from the workspace to the function, output parameters from the function to the workspace.
Function:
In contrast to a script, workspace variables are not automatically known within a function and are also not automatically changed by a function. The data transfer between workspace and function requires input and output parameters. After the function has been processed, only those variables used in a function that were transferred as output parameters are available in the workspace.
The syntax of the function header is:
function output=function name(input)
The call (from the command line or from a script or another function) is:
output=function name(input)
Data flow:
The transfer of data between functions and workspace, as well as the use of files and user queries, can become quite complicated with complex problems. In such cases, the data flow between the functions involved, data sources (e.g. user input, files) and data sinks (e.g. screen output, files) should be carefully planned in order to avoid accidental data loss or programme errors. Data flow diagrams are a graphical representation of the data flow:
en.wikipedia.org/wiki/data-flow-diagram
Control flow:
The chronological order in which the commands of a programme are processed is referred to as the control flow. In Matlab, this normally corresponds to the sequence of commands in the programme code, but is influenced by control structures such as case distinctions and loops.
Flowcharts are a good way of planning and visualising the control flow of a programme: de.wikipedia.org/wiki/Programme flowchart
Case differentiation:
A case differentiation consists of a condition and a sequence of commands. The condition must be formulated in such a way that it is either true or false. If it is true, the command part is executed once, otherwise it is skipped in the programme sequence. Matlab offers "if - elseif - else" and "switch" as options for case distinctions.
Loop:
A loop also consists of a condition and a sequence of commands, the difference to case differentiation is that the commands can be executed multiple times depending on the condition.
In a counting loop (usually implemented as a for loop), a variable is counted up or down in equal steps from a start value as a condition until a final value is reached.
In the more general form of a conditional loop (usually implemented as a while loop), the commands are executed again and again until the specified condition is no longer met.
Data types:
Normally, Matlab is mainly used to process numbers, which are always represented by Matlab as floating point numbers (double). However, there is also data for which it makes no sense to assume fractional values and which are therefore represented as integers (int). Truth values that can only be either true (1) or false (0) are called logical in Matlab. If text is to be processed, letters (char) are used as the data type. We will also familiarise ourselves with structures as data types in the course.