Professional Documents
Culture Documents
Laboratory Exercise 3
Matrix
From: mccormick.northwestern.edu
Objective
Material
MATLAB r2020a or any version
Procedure: write the scripts on matlab command window. The indented figures are the answers to the
scripts. Do not include the bold texts. Observe the results and perform the task after.
1. row vector
>> v = [1 4 7 10 13]
v=
1 4 7 10 13
>> w = [1;4;7;10;13]
w=
10
13
3. transpose operation
>> w = v’
w=
10
13
>> v(1:3)
ans =
147
>> v(3:end)
ans =
7 10 13
6. To enter a matrix A
>> A = [1 2 3; 4 5 6; 7 8 9]
A=
123
456
789
7. view a particular element in a matrix by specifying its location
>> A(2,1)
ans =
>> A(3,3) = 0
A=
123
456
780
9. sub-matrix
extract a submatrix B consisting of rows 2 and 3 and columns 1 and 2 of the matrix A
10. To interchange rows 1 and 2 of A, use the vector of row indices together with the colon
operator
>> C = A([2 1 3],:)
C=
456
123
7 80
Task
Perform the following tasks and record the answers. Provide the screenshots of the scripts used, results,
and workspace. You can use matlab for pc or matlab for android.
Use minimum command lines and number of scripts as possible.
Clear the editor, workspace and command window of matlab before performing the task.
Answer the following:
1. Create matrix ‘a’ as shown below:
a=
12345
23456
34567
45678
2. Create a column vector v, from the elements of the 4th row of the matrix a:
3. delete the fourth row of ‘a’ using [ ]
4. delete the fifth column of ‘a’ [ ]
Paste the screenshots of your answers on a ms word document with the answers to the questions. Save
and submit as pdf format. Use the format below
LABORATORY EXERCISE NO. 3
___________TITLE__________
Name : ___________________________________________
Section: _______________________________
Task:
1.
2.