Coding Basics
A=[1,2,3,4,5]
% Above statement when executed will define a row matrix variable named as A, of five elements and will also print it on the command window
A =
1 2 3 4 5
B=[1;2;3;4;5]
% Above statement when executed will define a column matrix variable named as B, of five elements and will also print it on the command window
B =
1
2
3
4
5
C = A*B\'
% Above statement will produce an error as the matrix multiplication is incompatible.
% A mat dimension is 1x5 and B\' mat dimension is also 1x5
C = B*A
C =
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
A(1:end)
%Above statement will print values of mat A from index to 1 till last index(inclusive).
A =
1 2 3 4 5
A(1:2)
%Above statement will print the values of mat A from index 1 to index 2(inclusive).
ans =
1 2
B(1:2,3)
%Above statement will produce an error since mat B is a one-dimensional matrix of shape (5x1) and we are searching for two dimensions.
B(length(B)-2)
%Above statement will print the 3rd element of mat B as the length of mat B is 5.
ans = 3