Question 5 Problem Definition Write a MATLAB script that uses nested loops to create a 100 by 100 element 2D array representing an image that shades from white at the image edges to black in the image centre (see image below). Your script should save the image in a file called test5.png. Testing The image file produced should shade from white at the image edges to black in the image centre. Any image that graduates colour continuously from light at the edges to black in the centre is acceptable. An image that comes from one simple implementation is: Coding You can implement this code by making the pixel intensity increase with distance from the centre of the image. Think of how you might measure this distance for rows and columns. Write your code in a MATLAB script called q5.m and save it into your week4practice folder.
Added by Benjamin R.
Close
Step 1
Step 1: Create a 100 by 100 matrix to represent the image. Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 78 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Akash M.
Write a MATLAB function that draws the Gershgorin row set of a given matrix in the complex plane. Call your function "growset". Its five input arguments are as follows (in order): - argument 1: the number of the figure where the Gershgorin set is to appear (a positive integer); - argument 2: an integer with value 0 or 1, depending on whether the Gershgorin set is filled or not, respectively; - argument 3: the given matrix (a square array of complex numbers); - argument 4: the color of the Gershgorin set (a string); - argument 5: the line width (thickness) of the circles when the set is not filled (a positive number). Its two output arguments are as follows (in order): - argument 1: a column vector of nonnegative numbers that has as its components the deleted row sums of the given matrix; - argument 2: an integer with value 1 if the Gershgorin row set can determine that the matrix is nonsingular, and with value 0 otherwise. You must use your own "gdisk" function to draw the Gershgorin set. In addition, you are to plot the eigenvalues of the matrix, which should lie in the Gershgorin set, using a black asterisk (*). The eigenvalues can be computed with the MATLAB "eig" function. "gdisk" Function: function gdisk(num, cd, center, r, col, lw) x = real(center); % separating real component from center y = imag(center); % separating imaginary component from center d = r*2; % diameter if cd == 0 % for a circle for i=1:num figure(i) % number of figure px = x-r; % real component py = y-r; % imaginary component h = rectangle('Position',[px py d d],'Curvature',[1,1]); % plot circle using rectangle command daspect([1,1,1]); % correcting aspect ratio h.LineWidth = lw; % thickness of circle h.EdgeColor = col; % color of circle end elseif cd == 1 % for a disk for i=1:num figure(i) % number of figure px = x-r; % real component py = y-r; % imaginary component h = rectangle('Position',[px py d d],'Curvature',[1,1]); % plot disk using rectangle command daspect([1,1,1]); % correcting aspect ratio h.FaceColor = col; % color of disk set(h, 'EdgeColor', 'none'); % no edge color end end end
Sri K.
First (20%) write a function named calcRoomArea that 1. Takes as input the length and width of a room 2. Returns two outputs area and n_tiles where • area: is the area of a room with dimensions length and width in feet • n_tiles: is the number of tiles than you need to buy to cover the floor completely; each tile is 12 x 18 inches Then (30%) write a script named myRoom to test your function 1. Open a text file named room_size.txt for reading only • The file contains only two lines • Line 1 contains the length of the room in feet • Line 2 contains the width of the room in feet 2. After reading these two values, close the file. 3. Call the function you created using the two numbers read from the file 4. Display the following message in one line ‘For a room ____ square feet you need to buy ____ tiles measuring 12x18 inches each.’ (Display the correct dimensions and correct number of tiles to buy.) Then (50%) add to the script code to display in a figure window the floor as follows: 1. Assume that you have tiles of two different colors, black and red. 2. Display the floor using alternating rows of black and red tiles resulting in a checkerboard pattern, like in the picture Hint: to draw each tile, use the command patch(x,y,'color'), where the elements of vectors x and y are pairs of coordinates corresponding to the vertices of a patch (a tile) and 'color' is a string, one of the standard colors. Note: the dimensions of the floor may not be an exact multiple integer of the tile dimensions. Extra credit (20%) Place the whole tiles in the center of the room in both dimensions and the partial tiles in the periphery (see picture).
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD