English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The behavior of the MATLAB environment is like a super complex calculator. You can enter commands at the >> command prompt.
MATLAB is an interpreted environment. In other words, you give a command and MATLAB executes the command immediately.
Enter a valid expression, such as,
5 + 5
Then press ENTER
When you click the Execute button or type Ctrl + When E is reached, MATLAB will execute it immediately, and the returned result is-
ans = 10
Let's take a few more examples-
3 ^ 2 % 3 raised to the power of 2
When you click the Execute button or type Ctrl + When E is reached, MATLAB will execute it immediately, and the returned result is-
ans = 9
Another example,
sin(pi /2) % sine of angle 90o
When you click the Execute button or type Ctrl + When E is reached, MATLAB will execute it immediately, and the returned result is-
ans = 1
Another example,
7/0 % Divide by zero
When you click the Execute button or type Ctrl + When E is reached, MATLAB will execute it immediately, and the returned result is-
ans = Inf warning: division by zero
Another example,
732 * 20.3
When you click the Execute button or type Ctrl + When E is reached, MATLAB will execute it immediately, and the returned result is-
ans = 1.4860e+04
MATLAB provides some special expressions for certain mathematical symbols, such as pi representing π, Inf representing ∞, and i (and j) representing √-1et al.NanRepresents 'not a number'.
The semicolon (;) indicates the end of a statement. However, if you want to hide and hide the MATLAB output of an expression, add a semicolon after the expression.
Zum Beispiel,
x = 3; y = x + 5
When you click the Execute button or type Ctrl + When E is reached, MATLAB will execute it immediately, and the returned result is-
y = 8
The percentage sign (%) is used to indicate comment lines. For example,
x = 9 % Assign value9Assign to x
You can also use block comment operators %{ and %} to write comment blocks.
The MATLAB editor includes tools and context menu items that can help you add, delete, or change the format of comments.
MATLAB supports the following common operators and special characters-
Operator | Destination |
---|---|
+ | Addition; addition operator. |
- | Subtraction; subtraction operator. |
* | Scalar and matrix multiplication operator. |
.* | Array multiplication operator. |
^ | Scalar and matrix power operator. |
.^ | Array power operator. |
\ | Link operator. |
/ | RechterDivisionsoperator. |
.\ | ArraylinkerDivisionsoperator. |
./ | ArrayrechterDivisionsoperator. |
: | Doppelpunkt; generiert Elemente mit regelmäßigen Abständen und zeigt Zeilen oder Spalten an. |
( ) | Klammern; schließt Funktionsparameter und Arrayindizes ein; überschreibt Priorität. |
[ ] | Klammern; befestigt Arrayelemente. |
. | Punkt. |
... | Punkt; gibt den Zeilenfortsetzungsoperator an. |
, | Komma; trennt Anweisungen und Elemente in einer Zeile. |
; | Semikolon; trennt Spalten und unterdrückt die Anzeige. |
% | Prozentzeichen; gibt Anmerkungen an und gibt das Format an. |
_ | Bezugssymbol und Transpositionsoperator. |
._ | NichtkonjugierterTranspositionsoperator. |
= | Zuweisungsoperator. |
MATLABunterstütztfolgendebesondereVariablenundKonstanten-
Name | Bedeutung |
---|---|
ans | Letzte berechnete Antwort. |
eps | Fließkommazahlgenauigkeit. |
i,j | Der imaginäre Einheitswurzel√-1. |
Inf | Unendlich. |
NaN | Nicht definierte numerische Ergebnisse (keine Zahl). |
pi | π |
Der Variablenname besteht aus Buchstaben, gefolgt von beliebiger Anzahl von Buchstaben, Ziffern oder Unterstrichen.
MATLABist case-sensitive.
Der Variablenname kann beliebige Länge haben, aber MATLAB verwendet nur die ersten N Zeichen, wobei N von der Funktion angegeben wird namelengthmax.
saveBefehl speichert alle Variablen im Arbeitsbereich in einer Datei mit der Erweiterung .mat im aktuellen Verzeichnis.
Zum Beispiel,
save myfile
Sie können ihn später jederzeit verwendenloadBefehl zum Neuladen der Datei.
load myfile