CREATE A ROW VECTOR AND COLUMN VECTOR IN MATLAB
CREATE A ROW VECTOR AND COLUMN VECTOR IN MATLAB
AIM: To create a Row Vector and Column Vector in MATLAB.
GUI Used: MATLAB R2020a
OBJECTIVES:
- Some Basic Theories of Matrices, Rows and Columns will be discussed.
- We will try to follow few steps to create the programming and the codes will be explained.
- Codes will be evaluated in the command window.
BASIC THEORIES:
In order to know about the rows and column vector, we will highlight few definitions;
- A Matrix is a two-dimensional array of data elements arranged in Rows and Columns. The elements can be numbers, logical values (true and false), date and time, strings or some other MATLAB data type. Even a single number is stored as Matrix. Let’s have real life example of a Matrix;
Here is a table of marks obtained by three students in four subjects:
|
Mathematics |
English |
Science |
Geography |
|
|
Student_1 |
85 |
72 |
79 |
90 |
|
Student_2 |
70 |
85 |
75 |
71 |
|
Student_3 |
99 |
80 |
87 |
67 |
So, we can write it in a matrix form. Here it is;
Marks obtained by three students in four subjects=
…… (i)
- A vector having only one row is called Row Vector or Row Matrix. 1×N is the size of a Row Vector where N is the number of columns.
Let’s take an example of a Row vector;
Suppose, we want to know the numbers obtained by Student_3 in each subject from the matrix (i), then we have to print the 3rd row;
Marks Obtained by Student_3 =
……(ii)
Matrix (ii) is a row vector where it has only one row and four column.
- A vector having only one column is called Column Vector or Column Matrix. M×1 is the size of a Column Vector where M is the number of rows. Let’s take an example of a column vector;
Suppose, we want to know the numbers obtained by all three Students in Mathematics from the matrix (i), then we have to print the 1st column;
Marks obtained in Mathematics=
……(iii)
Matrix (iii) is a column vector where it has only one column and three rows.
PROCEDURES:
Steps to be followed to create a Row Vector and a Column Vector;
- Step1: Open MATLAB.
- Step2: Click on New Script to open the Editor Window.
- Step3: Input code need to be written here and then click on Save option to save the program as a M-file.
- Step4: Commands need to enter in the command window to run the programming to get an output.
PROGRAMMING:
clear
close all
% A program for getting output as a Row Vector and Column Vector
marks_obtained_by_all_three_students_in_four_subjects=[85,72,79,90;70,85,75,71;99,80,87,67];
% To get the marks obtained by Student_3 in all for four subjects
marks_obtained_by_student_3=marks_obtained_by_all_three_students_in_four_subjects(3,(1:4));
marks_obtained_in_mathematics=marks_obtained_by_all_three_students_in_four_subjects((1:3),1);
CODE EXPLANATION:
To create a row vector and a column vector in MATLAB, we have created the above Program where,
clear: It removes items from workspace, freeing up system memory.
close all: It deletes all figures whose handles are not hidden.
clc: It clears Command Window.
In the Code, we have used comma (,) and semicolon (;) to create a Row and Column respectively in the source matrix ‘marks_obtained_by_all_three_students_in_four_subjects’ .
To get the row vector as an Output we have used the theory of Sub Matrix or Sub Array. Here the colon (:) represents the Range Operator. The Output result of ‘marks_obtained_by_student_3’ and ‘marks_obtained_in_mathematics’ are the Row Vector and Column Vector Respectively.
OUTPUT:
CONCLUSION:
So, we can conclude that these are the processes need to be followed to create a Row Vector and a Column Vector in MATLAB.
References:
1.https://in.mathworks.com/help/matlab/math/creating-and-concatenating-matrices.html