The recommended deadline for all labs is 2022-10-14.
The strict deadline for all labs is the date of the exam.
Exam, conducted online via Zoom. Exam is graded on the scale Fail/3/4/5.
Exam date and time: 25th of October, 13.15-15.00.
Reference particular element in a vector v at index n |
v(n) |
Documentation |
Assign new value to an element in a vector v at index n |
v(n) = new_value |
Documentation |
Reference particular element in a matrix M at row row and column column |
M(row, column) |
Documentation |
Assign new value to an element in a matrix M at row row and column column |
M(row, column) = new_value |
Documentation |
Refer to all elements in a row n in a matrix M |
M(n, :) |
Documentation |
Refer to all elements in a column n in a matrix M |
M(:, n) |
Documentation |
Number of rows in a matrix M |
size(M, 1) |
Documentation |
Number of columns in a matrix M |
size(M, 2) |
Documentation |
Number of elements in a vector v |
length(v) |
Documentation |
Print value of a variable var |
disp(var) |
Documentation |
Clear workspace | clear; |
Documentation |
Create regularly-spaced vector starting from the number from to the number to with step step |
v = from:step:to |
Documentation |
Create unit-spaced vector starting from the number from to the number to (the same as from:1:to ) |
v = from:to |
Documentation |
Square root of x |
sqrt(x) or (x)^0.5 or (x)^(1/2) |
Documentation |
And | && |
Documentation |
Or | || |
Documentation |
Not | ~ |
Documentation |
Determine equality | a == b |
Documentation |
Determine inequality | a ~= b |
Documentation |
Order of operations in Matlab | See documentation | Documentation |
if condition
statements
elseif another_condition
statements
else
statements
end
values
to the variable value
.
Documentation
for value = values
statements
end
name
, where y1,...,yN
are output variables (put your variables instead of ...
) and x1,...,xM
are input variables.
Documentation
function [y1,...,yN] = name(x1,...,xM)
a = [-1, 6, 0, 4, 6];
indices1 = find(a > 1); % indices1 == [2, 4, 5]
indices2 = find(a == 6); % indices2 == [2, 5]
To select values from the vector use
a = [-1, 6, 0, 4, 6];
indices = find(a > 1); % indices1 == [2, 4, 5]
values = a(indices); % values == [6, 4, 6]
To find string in a cell array of strings use contains():
A = {'fish', 'dog', 'cat', 'horse'};
index = find(contains(A, 'dog')); % index == 2
Or ismember() (returns an array with 1 where the data in A is found in B):
A = {'dog','cat','fish','horse'};
B = {'dog','mouse','fish'};
res = ismember(A, B); % res == [true, false, true, false] or [1, 0, 1, 0]
segment_start_point = [59.6569444500000 17.9522222166667]; % lat and lon
segment_end_point = [59.6519444500000 17.9186111166667]; % lat and lon
result = azimuth(segment_start_point(1), segment_start_point(2), segment_end_point(1), segment_end_point(2)); % result == 253.6074
a = [3, 6, 4, 3, 4, 5];
result = unique(a); % result == [3, 4, 5, 6]
Unique also works with matrices:
a = [3, 6;
4, 3;
3, 6];
result = unique(a, 'rows'); % result == [3, 6; 4, 3]
a = [3, 6, 4, 3, 4, 5];
histogram(a); % try it!
Number of bins can be passed in the second argument of the function:
a = [3, 6, 4, 3, 4, 5];
histogram(a, 2); % try it!
Also, bins can be defined manually:
a = [3, 6, 4, 3, 4, 5];
histogram(a, [0, 3, 5, 6]); % try it!
Bins can be named:
a = [4, 3, 5];
histogram('Categories', {'First', 'Second', 'Third'}, 'BinCounts', a); % try it!
A = [7 1 7 7 4];
B = [7 0 4 4 0];
C = intersect(A,B); % C == [4, 7]
Also intersect works with matrices
A = [2 2 2; 0 0 1; 1 2 3; 1 1 1];
B = [1 2 3; 2 2 2; 2 2 0];
C = intersect(A, B, 'rows'); % C == [1, 2, 3; 2, 2, 2]
res = strsplit('ABCD_DCBA', '_'); % res == {'ABCD', 'DCBA'}
arc_length = distance(37, -76 , 37, -9);
arc_length_in_nm = deg2nm(distance(37, -76 , 37, -9));