MATLAB Quick start

Create matrix

1
2
3
4
5
6
% Direct method
a = [1, 2, 3; 4, 5, 6; 7, 8, 9];

% colon 1D matrix (start : step size : end) The step size is 1, which can be omitted.
b = 1:1:10; % 1,2,...10
b = 1:10; % Equivalent to above

a
b

1
2
3
4
% function generation
% linspace(start, end, number of elements), Arithmetic generates a 1D matrix with the specified number of elements.
% If the number of elements is omitted, the default is 100.
c = linspace(0, 10, 5);

c

1
2
3
4
5
6
7
% function generation
% special matrix
e = eye(4); % eye(dimension) unit array
z = zeros(1, 4); % zeros(dimension) all 0
o = ones(4, 1); % ones(dimension) all 1
r = rand(4); % rand(dimension) 0 to 1 distributed random array
rn = randn(4); % randn(dimension) 0 mean, Gaussian random array

e
z
o
r
rn

Matrix Operations TODO


MATLAB Quick start
https://www.hardyhu.cn/2022/02/21/MATLAB-Quick-start/
Author
John Doe
Posted on
February 21, 2022
Licensed under