a)
The given array consists of 4 rows and 5 columns with the total elements of 4 5 20 .
The size of an array is represented as number of rows number of columns .
Write the MATLAB code to create the given array using Equation (1).
array1=[0.0 0.5 2.1 -3.5 6.0;0.0 -1.1 -6.6 2.8 3.4;2.1 0.1
0.3 -0.4 1.3;1.1 5.1 0.0 1.1 -2.0]
array1 =
Type the following given code in the MATLAB command window to find the size of
array1 .
size(array1)
ans =
4 5
b)
Write the MATLAB code to create the given array using Equation (1).
array1=[0.0 0.5 2.1 -3.5 6.0;0.0 -1.1 -6.6 2.8 3.4;2.1 0.1
0.3 -0.4 1.3;1.1 5.1 0.0 1.1 -2.0]
array1 =
The command array11,4 represents the value present at first row and fourth column
of array1.
Type the following given code in the MATLAB command window to find the value of
array11,4 .
array1(1,4)
ans =
-3.5000
c)
Write the MATLAB code to create the given array using Equation (1).
array1=[0.0 0.5 2.1 -3.5 6.0;0.0 -1.1 -6.6 2.8 3.4;2.1 0.1
0.3 -0.4 1.3;1.1 5.1 0.0 1.1 -2.0]
Press enter to execute the above code. The output is,
array1 =
The command array1:,1:2:5 represents an array consists of first, third and fifth
column of array1.
Type the following given code in the MATLAB command window to find the values of
array1:,1:2:5 .
array1(:,1:2:5)
ans =
0 2.1000 6.0000
0 -6.6000 3.4000
2.1000 0.3000 1.3000
1.1000 0 -2.0000
0 2.1 6
2 6.6 3.4
Thus, the value of array1:,1:2:5 is
2.1 0.3 1.3
1.1 0 2
Type the following given code in the MATLAB command window to find the size of
array1:,1:2:5 .
size(array1(:,1:2:5))
ans =
4 3
d)
Write the MATLAB code to create the given array using Equation (1).
array1=[0.0 0.5 2.1 -3.5 6.0;0.0 -1.1 -6.6 2.8 3.4;2.1 0.1
0.3 -0.4 1.3;1.1 5.1 0.0 1.1 -2.0]
array1 =
The command array113,end represents the elements of first and third rows of last
column of array1.
Type the following given code in the MATLAB command window to find the values of
array1 13,end .
array1([1 3],end)
ans =
6.0000
1.3000
6
Thus, the value of array113,end is
1.3
Type the following given code in the MATLAB command window to find the size of
array1 13,end .
size(array1([1 3],end))
2 1