From charlesreid1

Line 56: Line 56:
|Rand (random numbers)
|Rand (random numbers)
|<syntaxhighlight lang="matlab">
|<syntaxhighlight lang="matlab">
>> rand(3,2)
>> rand(3,2);
</syntaxhighlight>
</syntaxhighlight>
|<math>
|<math>
Line 70: Line 70:
|Meshgrid
|Meshgrid
|<syntaxhighlight lang="matlab">
|<syntaxhighlight lang="matlab">
>> [x,y] = meshgrid(1:4,1:4)
>> [x,y] = meshgrid(1:4,1:4);
</syntaxhighlight>
</syntaxhighlight>
|<math>
|<math>
Line 94: Line 94:
</math>
</math>
|-
|-
|Magic (magic square matrix; the sum of each row and column is equal to the same value)
|Magic (magic square matrix)
 
(The sum of each row and column is equal to the same value)
 
|<syntaxhighlight lang="matlab">
|<syntaxhighlight lang="matlab">
>> magic(4);
>> magic(4);

Revision as of 05:12, 26 November 2010

Matrices

Basics

See Introduction to Matlab

Special matrices/vectors

Name (matrix type) Matlab syntax Result
Ones
>> ones(3,2);
$ \left[ \begin{array}{cc} 1 & 1 \\ 1 & 1 \\ 1 & 1 \end{array} \right] $
Zeros
>> zeros(3,1);
$ \left[ \begin{array}{cc} 0 \\ 0 \\ 0 \end{array} \right] $
Eye (identity)
>> eye(3);
$ \left[ \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array} \right] $
Rand (random numbers)
>> rand(3,2);
$ \left[ \begin{array}{cc} 0.21955 & 0.27560\\ 0.42385 & 0.62212\\ 0.53343 & 0.69182 \end{array} \right] $
Meshgrid
>> [x,y] = meshgrid(1:4,1:4);
$ x = \left[ \begin{array}{cccc} 1& 2& 3& 4\\ 1& 2& 3& 4\\ 1& 2& 3& 4\\ 1& 2& 3& 4 \end{array} \right] $

$ y = \left[ \begin{array}{cccc} 1& 1& 1& 1\\ 2& 2& 2& 2\\ 3& 3& 3& 3\\ 4& 4& 4& 4 \end{array} \right] $

Magic (magic square matrix)

(The sum of each row and column is equal to the same value)

>> magic(4);
$ \left[ \begin{array}{cccc} 16& 2& 3& 13\\ 5& 11& 10& 8\\ 9& 7& 6& 12\\ 4& 14& 15& 1 \end{array} \right] $

Functions

magic

repmat




linspace

logspace

length

det

x(end)

sort

find

max

min

diag

size

flipud

fliplr

Operators

Input/output

Switches

Functions

Graphics

Examples

Fluid mechanics

Heat transfer

Optimization

Statistics

See also