Exercise New
Exercise New
Ø 𝑒 ()*&.,
"#
-./01
$.&·(.#
Ø
2
l Create a 5*6 random two-dimensional array A, and use the logical 1 identifier to find all
elements in A that are greater than 0.3 and less than 0.7, and assign them to B.
l Create a 4*4 two-dimensional array A with all values 0 an a 4*3 two-dimensional array B
with all values 1. Splice A and B into a 4*7 two-dimensional array.
3 2 0
l A = &−5 6 1-
1 0 2
Ø Use the “find” function to find the linear index of the non-zero elements of the A
matrix.
Ø Find the subscripts of the rows and columns in matrix A with element 0.
Ø Find the official documentation and learn more about the use of the “find” function.
1 25 7 20
8 90 30 18
l A = > B
12 23 15 176
50 0 31 9
Ø Add a fifth column and assign the values [1, 0, 2, 8] in matrix A.
Ø Sum of the number of rows and columns of matrix A.
Ø Assign the elements of columns 1, 3 and 5 of rows 2-4 of matrix A to matrix B.
Ø Assign A to matrix C, delete the first and third rows of C and display them.
Ø Rearrange matrix A into a matrix of 5 rows and 4 columns.
Ø Find the mean value for each column of matrix A.
Ø Find the mean value for each row of matrix A.
Ø Calculate the mean value of all elements in matrix A.
Ø Assign the first and last values of matrix A to nan.
Ø Calculate the mean of all element in matrix A, excluding nan.
Exercise 2.
l plot sin(20x) ·exp(-x) in the interval [0,5] using solid line, then plot ±exp(-x) on the same
graph using dashed line; add descriptions and change default font to Times New Roman
and font size to 15.
Exercise 3.
l Write a function in MATLAB that calculates the Euclidean distance between two vectors
,
u and v: C∑)(𝑢) − 𝑣) )
Exercise 4.
l plot contour for D((𝑥 − 0.5), + (𝑦 − 0.5), ) ∙ ((𝑥 + 0.5), + (𝑦 + 0.5), ) in the interval
[-0.8,0.8] × [-0.8,0.8] using blue line, then denote both minima using red cross; add axis
description and a title.
Exercise 5.
l Implement simple database storing people names and ages. Database should be stored in
a .mat file and accessed through a function ‘people.m’ that can work in four modes as
illustrated below (here, db_file is a string storing the database file name)
l Test your database using a sequence of commands below. The preferred format for storing
data is a structure. Please use a given list to start.
Ø Add [your name, your age] to the list; Display the list
Test your code using a given example. Rotating clockwise and rotation angle is calculated
using the following formula: mod([Your ID number],360).
Exercise 7.
l Given N × N rectangular grid, mark certain number of randomly selected nodes as
obstacles. Develop and implement an algorithm that searches for the (possibly shortest)
path from the bottom edge of the grid to its top edge assuming that possible moves are
only vertical or horizontal. The path must not pass through an obstacle. Visualize the grid,
obstacles and the path similarly as shown below. Test your code for various cases
(different value of N, different density of obstacles). Please use the given obstacle maps.