22/10/19 11:04 AM MATLAB Command Window 1 of 3
>> % Creates a 2x2 matrix
>> % The simplest way to create a matrix is
>> % to list its entries in square brackets.
>> % The ";" symbol separates rows;
>> % the (optional) "," separates columns.
>> A = [1 2; 3 4]
A =
1 2
3 4
>> B = [1,2; 3,4]
B =
1 2
3 4
>> % A scala
>> N = 5
N =
>> % A row vector
>> v = [1 0 0]
v =
1 0 0
>> % A column vector
>> v = [1; 2; 3]
v =
1
2
3
>> % Transpose a vector (row to column or % column to row)
>> v = v'
v =
1 2 3
>> % A vector filled in a specified range:
>> v = 1:0.5:3
v =
1.0000 1.5000 2.0000 2.5000 3.0000
22/10/19 11:04 AM MATLAB Command Window 2 of 3
>> % [start:stepsize:end], brackets are % optional
>> v = pi*[-4:4]/4
v =
Columns 1 through 8
-3.1416 -2.3562 -1.5708 -0.7854 0 0.7854 1.5708 2.3562
Column 9
3.1416
>> % Empty vector
>> v = []
v =
[]
>> % Creates a 2x3 matrix of zeros
>> m = zeros(2, 3)
m =
0 0 0
0 0 0
>> % Creates a 1x3 matrix (row vector)of ones
>> v = ones(1, 3)
v =
1 1 1
>> % Identity matrix (3x3)
>> m = eye(3)
m =
1 0 0
0 1 0
0 0 1
>> % Randomly filled 3x1 matrix (column % vector); see also randn
>> v = rand(3, 1)
v =
0.8147
0.9058
0.1270
>> % Creates a 3x3 matrix (!) of zeros
22/10/19 11:04 AM MATLAB Command Window 3 of 3
>> m = zeros(3)
m =
0 0 0
0 0 0
0 0 0
>>