Professional Documents
Culture Documents
Lec 2
Lec 2
Department of Mathematics
NED University of Engineering & Technology.
Yousuf Tufail ¯ Yousuf Tufail
tufail@neduet.edu.pk
Lecture 2
In the above array, we do not know what height belongs to which person.
In the above array, we do not know what height belongs to which person.
If height 1,height 2,height 3 and height 4 are the heights of Ali, Jimmy,
Lisa and John respectively.
In the above array, we do not know what height belongs to which person.
If height 1,height 2,height 3 and height 4 are the heights of Ali, Jimmy,
Lisa and John respectively.
Now, If we want to store this information in the form of array then
following command can be used.
In the above array, we do not know what height belongs to which person.
If height 1,height 2,height 3 and height 4 are the heights of Ali, Jimmy,
Lisa and John respectively.
Now, If we want to store this information in the form of array then
following command can be used.
fam heights new
In the above array, we do not know what height belongs to which person.
If height 1,height 2,height 3 and height 4 are the heights of Ali, Jimmy,
Lisa and John respectively.
Now, If we want to store this information in the form of array then
following command can be used.
fam heights new= [[‘Ali ’,num2str(height 1)]
In the above array, we do not know what height belongs to which person.
If height 1,height 2,height 3 and height 4 are the heights of Ali, Jimmy,
Lisa and John respectively.
Now, If we want to store this information in the form of array then
following command can be used.
fam heights new= [[‘Ali ’,num2str(height 1)],[‘ Jimmy
’,num2str(height 2)]
,[‘ Lisa ’,num2str(height 3)],[‘ John ’,num2str(height 4)]];
In the above array, we do not know what height belongs to which person.
If height 1,height 2,height 3 and height 4 are the heights of Ali, Jimmy,
Lisa and John respectively.
Now, If we want to store this information in the form of array then
following command can be used.
fam heights new= [[‘Ali ’,num2str(height 1)],[‘ Jimmy
’,num2str(height 2)]
,[‘ Lisa ’,num2str(height 3)],[‘ John ’,num2str(height 4)]];
fam heights new
In the above array, we do not know what height belongs to which person.
If height 1,height 2,height 3 and height 4 are the heights of Ali, Jimmy,
Lisa and John respectively.
Now, If we want to store this information in the form of array then
following command can be used.
fam heights new= [[‘Ali ’,num2str(height 1)],[‘ Jimmy
’,num2str(height 2)]
,[‘ Lisa ’,num2str(height 3)],[‘ John ’,num2str(height 4)]];
fam heights new
‘Ali 1.64 Jimmy 1.42 Lisa 1.56 John 1.80’
Solution
Solution
To call the entries from the array, you have to call the required positions.
Solution
To call the entries from the array, you have to call the required positions.
fam heights new(1:14)
Solution
To call the entries from the array, you have to call the required positions.
fam heights new(1:14)
‘Ali 1.64 Jimmy’
Dr. Muhammad Yousuf Tufail (NEDUET) Matlab Lecture 2 4 / 12
Working with the arrays
Example (2)
Example (2)
Find the second element in the fam heights new
Example (2)
Find the second element in the fam heights new
Solution
Example (2)
Find the second element in the fam heights new
Solution
fam heights new(10:19)
Example (2)
Find the second element in the fam heights new
Solution
fam heights new(10:19)
‘Jimmy 1.42’
Example (3)
Example (3)
Display all the values from fam heights new except first. i.e., Ali and his
height must not be printed.
Example (3)
Display all the values from fam heights new except first. i.e., Ali and his
height must not be printed.
Solution
Example (3)
Display all the values from fam heights new except first. i.e., Ali and his
height must not be printed.
Solution
There are two ways for this questions that are as below:
Example (3)
Display all the values from fam heights new except first. i.e., Ali and his
height must not be printed.
Solution
There are two ways for this questions that are as below:
Method 1:
Example (3)
Display all the values from fam heights new except first. i.e., Ali and his
height must not be printed.
Solution
There are two ways for this questions that are as below:
Method 1:
fam heights new(10:38)
Method 2:
Example (3)
Display all the values from fam heights new except first. i.e., Ali and his
height must not be printed.
Solution
There are two ways for this questions that are as below:
Method 1:
fam heights new(10:38)
Method 2:
fam heights new(10:end)
Example (3)
Display all the values from fam heights new except first. i.e., Ali and his
height must not be printed.
Solution
There are two ways for this questions that are as below:
Method 1:
fam heights new(10:38)
Method 2:
fam heights new(10:end)
Example (3)
Display all the values from fam heights new except first. i.e., Ali and his
height must not be printed.
Solution
There are two ways for this questions that are as below:
Method 1:
fam heights new(10:38)
Method 2:
fam heights new(10:end)
Example (3)
Display all the values from fam heights new except first. i.e., Ali and his
height must not be printed.
Solution
There are two ways for this questions that are as below:
Method 1:
fam heights new(10:38)
Method 2:
fam heights new(10:end)
Maximum function:
You can also round off the fraction upto any decimal place of your choice.
You can also round off the fraction upto any decimal place of your choice.
For example,
You can also round off the fraction upto any decimal place of your choice.
For example, ‘a’ can be round off upto 1 decimal place as below:
You can also round off the fraction upto any decimal place of your choice.
For example, ‘a’ can be round off upto 1 decimal place as below:
round(a,1)
You can also round off the fraction upto any decimal place of your choice.
For example, ‘a’ can be round off upto 1 decimal place as below:
round(a,1)
5.5
Solution
Solution
A=[1 4 5;2 9 8;2 9 9;-1 -4 -5];
Solution
A=[1 4 5;2 9 8;2 9 9;-1 -4 -5];
A
You will get the desired matrix
Dr. Muhammad Yousuf Tufail (NEDUET) Matlab Lecture 2 9 / 12
Calling the elements from the array
Solution
Solution
As 8 is given in the second row and third column.
Solution
As 8 is given in the second row and third column. Therefore desired result
will be:
Solution
As 8 is given in the second row and third column. Therefore desired result
will be:
A(2,3)
Solution
As 8 is given in the second row and third column. Therefore desired result
will be:
A(2,3)
8
Solution
As 8 is given in the second row and third column. Therefore desired result
will be:
A(2,3)
8
Example (6)
Display -4 from the matrix
Solution
As 8 is given in the second row and third column. Therefore desired result
will be:
A(2,3)
8
Example (6)
Display -4 from the matrix
Solution
A(4,2)
-4
Dr. Muhammad Yousuf Tufail (NEDUET) Matlab Lecture 2 10 / 12
Calling the elements from the array
Solution
Solution
A(2,:)
Solution
A(2,:)
2 9 8
Solution
A(2,:)
2 9 8
Example (8)
Display third column from the matrix
Solution
A(2,:)
2 9 8
Example (8)
Display third column from the matrix
Solution
A(:,3)
Solution
A(2,:)
2 9 8
Example (8)
Display third column from the matrix
Solution
A(:,3)
5
8
9
-5
Dr. Muhammad Yousuf Tufail (NEDUET) Matlab Lecture 2 11 / 12
Practice questions
Example (practice)
Call third row
Call fourth column
Call -5 from the matrix
Call first three values of the third row
Call last three values in the fourth column