Coding Basics
1. A=[1,2,3,4,5]
This command will reult in an array containing 5 elements which will be stored in a matrix of 1X5
OUTPUT
A =
1 2 3 4 5
2. B=[1;2;3;4;5]
This command will reult in a column containing 5 elements which will be stored in a matrix of 5X1
OUTPUT
B =
1
2
3
4
5
3. C = A*B'
This command will result in error because the dimensions of the matrix donot match with the matrix multiplication rules that is the no. of columns of the first matrix should be equal to the no. of rows of the second matrix
as A has 1X5 and B has 5X1 dimension so B' will have 1X5 dimension so the resultant matrix C is not possible
OUTPUT
Error using *
Inner matrix dimensions must agree.
4. C = B*A
This command will result in matrix multiplication as the dimensions are in coherent with matrix multiplication rules
as B has 5X1 dimension and A has 1X5 dimension so the resultant matrix C will have 5X5 matrix
OUTPUT
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
5. A(1:end)
This command will display elements in array A starting from first element to the last element
OUTPUT
ans =
1 2 3 4 5
6. A(1:2)
This command will display elements in array A starting from first element to second element
OUTPUT
ans =
1 2
7. B(1:2,3)
This command will display elements starting from 1 to 2 of third column but as B has dimensions of 5X1 so it has only one column so it will result in error
OUTPUT
Index exceeds matrix dimensions.
8. B(length(B)-2)
This command will display element of number which is the difference of length of B and 2
so, as B is 5X1 so 5-2 which is three so 3rd element will be displayed
OUTPUT
ans =
3