You are on page 1of 4

Basic Matlab Commands

Derrick Hasterok January 27, 2005

Introduction

Matlab has a multitude of syntax and basic commands. Begining to program in a new language can be a daunting task. This document is meant as a help to make getting started with Matlab a bit easier. Listed below is a few of the basic commands and a few of their properties. This list is not exhaustive, nor is it meant to be. The Matlab command help is your friend!

System Commands
cd clc clear close delete ls help mkdir pwd who whos why Change directory. Clears command window. Clears variables from workspace. Closes figures. Deletes file. Lists directry. Tells you how to use a command. Makes directory. Prints working directory. Lists current variables on workspace. Lists current variables and size. Just try it if you get annoyed.

3
3.1

Operators
Arithmetic operators
+ * .* ^ .^ / Plus Minus Matrix multiply Array multiply Matrix power Array power Right matrix divide 1

./

- Right array divide

3.2

Boolean operators
== ~= < > <= >= Equal Not equal Less than Greater than Less than or equal Greater than or equal

3.3
& | ~

Logical operators
- Logical AND - Logical OR - Logical NOT

3.4

Special commands
: ( ) [ ] . .. ... , ; % = . Span operator [1:5] = [1 2 3 4 5] Operation grouping Vector and matrix delimiter Decimal point Parent directory Continuation of command to next line Separator End line or row Comment Assignment operator String delimiter Transpose Complex conjugate transpose

Basic Syntax
if else elseif end for while break continue function return Conditionally execute statements. IF statement condition. IF statement condition. Terminate scope of FOR, WHILE, SWITCH, TRY and IF statements. Repeat statements a specific number of times. Repeat statements an indefinite number of times. Terminate execution of WHILE or FOR loop. Pass control to the next iteration of FOR or WHILE loop. Add new function. Return to invoking function.

error disp feval

- Display error message and abort function. - Display an array. - Execute function specified by string.

5
5.1

Elementary Math Functions


Trigonometric
sin asin cos acos tan atan atan2 Sine. Inverse sine. Cosine. Inverse cosine. Tangent. Inverse tangent. Four quadrant inverse tangent.

5.2

Basic
sqrt exp log log10 factorial Square root. Exponential. Natural logarithm. Common (base 10) logarithm. Factorial function.

5.3

Complex
abs conj real imag isreal Absolute value. Complex conjugate. Complex real part. Complex imaginary part. True for real array.

5.4

Rounding
floor ceil round mod Round towards minus infinity. Round towards plus infinity. Round towards nearest integer. Modulus.

5.5

Matrix and Other


norm det inv eig cross Matrix or vector norm. Determinant. Matrix inverse. Eigenvalues and eigenvectors. Vector cross product. 3

dot

- Vector dot product.

File input/output
input load save - Prompt for user input. - Load workspace from MATLAB (MAT) file. - Save data to MATLAB (MAT) file.

7
7.1

Plot commands
2D Graphs
plot loglog semilogx semilogy axis hold title xlabel ylabel get set Linear plot. Log-log scale plot. Semi-log scale plot. Semi-log scale plot. Control axis scaling and appearance. Hold current graph. Graph title. X-axis label. Y-axis label. Gets plot properties. Sets plot properties.

7.2

Matlab PLOT styles


Color y m c r g b w k yellow magenta cyan red green blue white black Line Type : -. -solid dotted dashdot dashed Marker Type . o x + * s d v ^ < > p h point circle x-mark plus star square diamond triangle (down) triangle (up) triangle (left) triangle (right pentagram hexagram

You might also like