FAMU-FSU College of Engineering Department of Electrical & Computer Engineering EEL3002L - ECE Engineering Tools Laboratory Lab Number 4 Plotting in MATLAB Professor Bing W. Kwan Revised: Spring 2024 EEL3002L Lab #4 ECE Tools Lab Lab Number 4 Plotting in MATLAB Objective The main goal of this lab is to enable the students to exploit MATALB plotting functions to create basic but commonly used 2-D and 3-D graphs. The focus is placed on (1) plotting 2-D line, bar, and area graphs; (2) plotting 3-D line, mesh, and surface graphs; (3) editing graphs; and (4) printing and exporting figures. Outline The scope of this lab is outlined as follows: 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 Overview of MATLAB plots Two-dimensional (2-D) plotting functions Three-dimensional (3-D) plotting functions Multiple plots in one figure Editing plots Printing and exporting figures In-lab experiments Lab report 42 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab Pre-lab Assignments A. Reading Lab #4 manual Before coming to conduct the in-lab experiments, the students are required to read and learn about the topics outlined above. This is a worthwhile exercise that serves to complement their learning from the hands-on experiences during the in-lab session. A comprehensive exposition of the subject matter is included in this lab manual. In addition, the students are encouraged to seek more detailed pertinent information from the following references: Complete and extensive help files can be found by searching the online documentation during an active MATLAB session. Supplementary documents and resources supporting the use of MATLAB are available at the MathWorks website: www.mathworks.com Lecture Notes #1 & Lab #1 Manual Learning MATLAB - Quick Start Lecture Notes #2 & Lab #2 Manual -- Notes: Using MATLAB for Linear Algebra Problems - Part I (A & B). -- Manual: Using MATLAB for Linear Algebra Problems - Part I Lecture Notes #3 Using MATLAB for Linear Algebra Problems - Part II Lecture Notes #4 Plotting in MATLAB (To be posted after the Tuesday lecture this coming week.) B. Pre-lab exercises Refer to Pre-lab Exercise Set #4, which is posted separately. 43 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab 4.1 Overview of MATLAB Plots A variety of 2-D and 3-D MATLAB plots can be generated requiring very little, if any, programming. In this lab, the students will learn how to create several basic but commonly used plots. These include the line, bar, area, and surface graphs. The basic procedures for editing, printing, and exporting graphs are also explored. In general, 2-D plotting functions are used to draw graphs for visualizing functions of one variable having the form: y f ( x) where xmin x xmax Similarly, 3-D plotting functions are used to draw line, mesh, and surface graphs for viewing functions of two variables of the form: z f ( x , y) where xmin x xmax , ymin y ymax 4.2 Two-dimensional (2-D) Plotting Functions A. Line graphs ezplot Two basic forms of syntax: 1. ezplot(fun_x, [xmin, xmax]) 2. ezplot(fun_xy, [xmin, xmax, ymin, ymax]) The first form creates a 2-D line plot of y versus x according to the relation explicitly defined by y = f(x). The character string fun_x is used to define the function f(x). The second form creates a 2-D line plot of y versus x according to the relation implicitly defined by the equation f(x, y) = 0. Similarly, the character string fun_xy specifies the function f(x, y). The array [xmin, xmax, ymin, ymax] specifies the ranges of x and y. When the range specification is omitted, the default ranges are: 2 x 2 , 2 y 2 44 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab Example Use ezplot to draw the graph of y versus x defined explicitly by the relation: y f ( x) x 2 3, 2 x 5 >> ezplot('x.^2- 3', [-2, 5]) % Vectorization is used. >> grid on 45 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab Example Use ezplot to draw the graph of y versus x defined implicitly by the relation: f ( x , y ) x 2 y 2 4 0, 4 x 4 , 3 x 3 >> ezplot(@(x, y) (x.^2 + y.^2 - 4), [-4, 4, -3, 3]) >> grid on Remarks 1. The MATLAB function handle @ (at operator) is used to define the function f(x, y). 2. The function ezplot draws only one graph in the figure. 46 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab fplot This is another simple and easy to use MATLAB plotting function for drawing the graph of a 2-D function with the following characteristics: y f ( x), xmin x xmax , ymin y ymax Specifically, the range of values for both the x-axis and the y-axis may be specified. Unlike ezplot, however, it is suited for drawing multiple graphs in a single figure. The syntax of fplot has the basic form: fplot(FUN, LIMS) Remarks 1. FUN is the function to be plotted. It can be created by exploiting the MATLAB function handle @ as illustrated below. Example: The 2-D function f ( x) x1.5 7.5 may be created using the MATLAB function handle as follows: @(x)(x.^(1.5) - 7.5) % Specify f(x). 2. LIMS = [xmin,xmax,ymin,ymax]: Specify the range for x-axis and y-axis. = [xmin,xmax]: Specify range for x-axis only. 3. FUN can be extended to include multiple functions. This means several 2D functions sharing the same x-axis can be plotted in the same figure. 47 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab Example Use fplot to graph the following 2-D functions: y1 tan ( x), y 2 sin ( x), y3 cos ( x), where 4 x, y1 , y 2 , y3 , 4 The MATLAB commands are entered as follows: >> fplot(@(x)[tan(x),sin(x),cos(x)], 4*pi*[-1 1 -1 1]); >> grid on The 3 functions are plotted in a single figure as shown below: 48 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab plot Basic syntax: plot(x1, y1, x2, y2,..., xn, yn) This function plots n 2-D line graphs in a figure. Each line with distinct color is plotted for the corresponding data set (xk, yk), namely xk versus yk, where 1 k n. Example >> x = [-pi : pi/100 : pi]; >> y = tan(sin(x)) - sin(tan(x)); >> plot(x, y), grid on The above command sequence produces a single line plot with n = 1 as shown in the following figure: 49 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab plotyy Basic syntax: plotyy(x1, y1, x2, y2) This function is used to create 2-D line plots for y1 versus x1 with y-axis labeling on the left and y2 versus x2 with y-axis labeling on the right. Example >> y1 y2 >> x = 0 : 0.01 : 20; = 200*exp(-0.05*x).*sin(x); = 0.8*exp(-0.5*x).*sin(10*x); plotyy(x, y1, x, y2), grid on The above command sequence produces the following graph: 410 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab semilogx, semilogy Basic syntax: semilogx(x1, y1, x2, y2,..., xn, yn) semilogy(x1, y1, x2, y2,..., xn, yn) The functions semilogx and semilogy plot the data on the logarithmic scale for the x-axis and y-axis, respectively. More specifically, semilogx(x1,y1,...) plots all the data sets with x-axis on log scale. semilogy(x1,y1,...) plots all the data sets with y-axis on log scale. Example >> x = 0: 0.1 : 10; >> semilogy(x,10.^(-x.*x/2)), grid on The above command sequence produces the following graph: 411 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab loglog Basic syntax: loglog(x1, y1, x2, y2,..., xn, yn) This function plots one line with distinct color for each data set (xk, yk), where 1 k n, on the logarithmic scale for both x-axis and y-axis. Example >> x = logspace(-1, 2, 50); >> loglog(x, exp(-sqrt(x))), grid on The above command sequence produces the following graph: 412 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab stairs Basic syntax: stairs(x, y) This function plots the data in y at the locations specified in x. Stair-step graphs are particularly useful for drawing time series of digitally sampled data. Example >> x = linspace(-2*pi, 2*pi, 40); >> stairs(x, sin(x)), grid on The above command sequence produces the following graph: 413 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab polar Basic syntax: polar(, ) This function plots data on the polar grid superimposed on the x-y plane. The data points are specified in the polar coordinates stored in the array pair (, ). This means each element in specifies the distance from the origin along the radial line that forms an angle specified by the corresponding element in . The angles in are measured counterclockwise with respect to the x-axis. Example >> theta = 0: 0.01 : 2*pi; >> rho = sin(2*theta).* cos(5*theta); >> polar(theta, rho) The above command sequence produces the following polar plot: 414 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab B. Bar graphs stem Basic syntax: stem(x, y) This function plots a 2-D graph displaying data as lines extending from a baseline along the x-axis. Specifically, stems (vertical lines) with heights proportional to the element values in y are extended from the x-axis locations defined by the elements in x. By default, each stem is terminated in a circle. Example >> x = 0 : 10; >> y = 0.75 * exp(-0.2*x); >> stem(x, y), grid on The above command sequence produces the following stem plot: 415 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab hist Basic syntax: hist(y, x) This function plots the histogram showing how the values in a data set are distributed. Specifically, the distribution is defined by the frequency counts of the data values in y belonging to the bins (intervals) whose centers are specified in x. Example >> x = -4 : 0.1 : 4; >> y = randn(10000, 1); >> hist(y, x), grid on The above command sequence produces the following histogram: 416 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab bar Basic syntax: bar(x, ‘grouped’), bar(x, ‘stacked’) This function displays the values in an (m n) matrix x as vertical bars with two basic display styles as described below: Style ‘grouped’ The n values in each row of x are displayed as a group of n vertical bars with proportional heights, thus resulting in m groups for x as a whole. The bars corresponding to the same column have the same color. Style ‘stacked’ The n values in each row of x are displayed as distinct colored segments of proportional heights. These segments are stacked to form a single vertical bar, thus resulting in m vertical bars for x as a whole. Hence, each bar is multicolored with proportional heights. The elements from the same column have the same color. Example >> y = 10*rand(3, 5) y = 2.7603 1.6261 9.5974 6.7970 1.1900 3.4039 6.5510 4.9836 5.8527 >> figure(1) >> bar(y, 'grouped'), grid on >> figure(2) >> bar(y, 'stacked'), grid on 2.2381 7.5127 2.5510 5.0596 6.9908 8.9090 The above command sequence produces bar graphs with two different styles as shown in the following: 417 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ‘grouped’style: ‘stacked’style: 418 Spring 2024 Professor B.W. Kwan ECE Tools Lab EEL3002L Lab #4 ECE Tools Lab C. Area graphs pie Basic syntax: pie(x) Extended syntax: pie(x, offset) This function draws a pie chart using the data in x. The elements in x are represented as slices with proportional areas in the pie chart. The optional vector offset is used to select a slice drawn with an offset from the center of the pie chart. Assigning a nonzero value to an element of offset will result in the corresponding slice in the pie chart being drawn with an offset. Example >> >> >> >> x = [1 3 0.5 2.5 2]; figure(1), pie(x) x_os = [0 1 0 0 0]; figure (2), pie(x, x_os) The above command sequence produces a regular pie chart and one with an offset slice. 1. Regular pie chart with no offset slice: 419 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 2. Pie chart with one offset slice: 420 Spring 2024 Professor B.W. Kwan ECE Tools Lab EEL3002L Lab #4 ECE Tools Lab 4.3 Three-dimensional (3-D) Plotting Functions The 3-D plotting functions are useful for viewing mathematical functions over a rectangular region. A. Line graphs plot3 Basic syntax: plot3(x1, y1, z1,...) This function displays a set of data points in the 3-D space. It is the analogue of the 2-D plot function. A line is plotted through the data points, which are defined by the corresponding elements of the triplet vector set (x1, y1, z1), each having the same length. These vectors typically vary with a common parameter t. In essence, plot3 produces multiple parameterized curves in the 3-D space when multiple triple vector sets are provided. Example >> t = 0: pi/100 : 4*pi; >> plot3(sin(0.75*t), cos(t), t) >> grid on The above command sequence produces the following helix-like curve: 421 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab B. Mesh graphs mesh Basic syntax: mesh(x, y, z) This function creates a wireframe surface specified by the elements of x, y, and z, where z = f(x, y). A wireframe surface is a collection of surface patches that are formed by straight lines connecting the grid points z(m, n) on the surface. Specifically, a surface grid point z(m, n) is determined by the 2-D coordinate pair (x(n), y(m)) of the rectangular grid defined by the coordinate vectors x_c and y_c. The wireframe line color is proportional to the surface height measured by z(m, n). Example >> >> >> >> x_c = [2 : 0.2 : 4]; y_c = [1 : 0.2 : 3]; [x, y] = meshgrid(x_c, y_c); z = (x - 3).^2 - (y - 2).^2; mesh(x, y, z) The above command sequence produces the following wireframe surface: Surface grid points 422 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab C. Surface graphs surf Basic syntax: surf(x, y, z) This function plots a surface of the form z = f(x, y) in essentially the same manner as mesh does. The only distinction is mesh displays a wireframe surface but only colors the connecting lines, whereas surf displays the connecting lines in black and the surface patches in color. The color for each patch is proportional to the surface height. Example >> >> >> >> [x, y] = meshgrid([-2 : 0.2 : 2]); z = -x.*y.*exp(-2*(x.*x + y.*y)); surf(x, y, z) xlabel('x'), ylabel('y') The above command sequence produces the following surface plot: 423 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab 4.4 Multiple Plots in One Figure The subplot command displays multiple plots in the same figure window. To partition the figure window into an (m n) matrix of small subplots, one enters the command: >> subplot(m, n, k) The index k, for 1 k mn, is used to identify the subplots in the matrix structure. It also specifies the position of a subplot in the (m n) matrix. The following figure illustrates the arrangement of 12 subplots in the (3 4) matrix structure (namely m = 3, n = 4): Subplot Subplot Subplot Subplot 1 2 3 4 Subplot Subplot Subplot Subplot 5 6 7 8 Subplot Subplot Subplot Subplot 9 10 11 12 Observe that the subplots are arranged in the matrix row-wise, starting from the top left, in accordance with the position index k in the ascending order. 424 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab Example >> >> >> >> >> >> t = 0 : pi/10 : 2*pi; [x, y, z] = cylinder(4*cos(t)); subplot(2, 2, 1); mesh(x) subplot(2, 2, 2); mesh(y) subplot(2, 2, 3); mesh(z) subplot(2, 2, 4); mesh(x, y, z) The above command sequence results in 4 subplots in a single figure arranged in the (2 2) matrix pattern as shown below: 425 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab 4.5 Editing Plots To ensure readability, MATLAB graphs are formatted such that (a) the axes have proper scales and tick marks, and (b) the lines have distinct styles and colors. Nevertheless, the default format can be edited to add descriptive labels, titles, legends, and other annotations to enhance the visualization of the data. MATLAB Plots can be edited using two approaches as described in the following. Using MATLAB functions at the command line or in an M-file This approach is not suited for this introductory lab as it requires more programming experience and advanced knowledge about MATLAB. Using the interactive plot-edit mode The MATLAB figure window supports a point-and-click editing mode. A user can enter this plot-edit mode to perform basic editing tasks which include selecting, cutting, copying, pasting, moving, and resizing objects. Other plot properties can also be modified. Two simple ways to enter the plot-edit mode are as follows: 1. Select the Edit Plot option on the figure window Tools menu. 2. Click the selection button in the figure window toolbar as depicted below. Click the arrow button to enable the edit mode. 426 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab 4.6 Printing and Exporting Figures MATLAB figures can be included in a variety of applications such as word processing, slide presentation, modification by a graphics program, and so on. Hence, exporting MATLAB figures in appropriate graphic formats supported by the target applications is essential. The basic means of exporting and printing figures generated in MATLAB are explored in this section. Exporting and printing figures often involve the graphical-user-interface (GUI) features which are initiated via the menu-bar in the MATLAB figure window depicted below. A. Using Print Preview It is good practice to preview the figure before printing or exporting. The Print Preview GUI dialog box allows a user to preview the figure before printing or exporting. In addition, the figure characteristics and properties can be set or adjusted. The preview dialog box can be opened using the following select-click sequence: File >> Print Preview B. Printing figures The basic options for printing a MATLAB figure are noted in the following. Printing on Microsoft Windows platforms MATLAB printing on Windows platforms uses the standard Windows Print dialog box. To open the Windows Print dialog box in an active figure window, one applies the following select-click sequence: File >> Print Note that clicking on the Print button in the Print Preview dialog box serves the same purpose. 427 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab To print the current active figure on the default printer, one simply enters the command: >> print Printing to a file One has the option of printing a figure to a file instead of sending it to a printer. In this case, the two basic options are as follows: Printing to a file on Windows platforms The standard Windows procedure for printing the current figure to a file involves the steps listed below: Step 1: Select and click File >> Print. Step 2: Select the check box Print to file. Step 3: Click the OK button, and then specify the output filename. Printing to a file using MATLAB commands One uses the print function to print from the MATLAB command line or from a program. A generic command line is featured below: >> print –dgraphic_format figure_name This will result in the current active figure to be exported as a graphics file having format graphic_format and filename figure_name. MATLAB selects the filename extension if it is not specified. The following two examples serve to illustrate the basic elements involved in the procedure. 428 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab Example To save the current figure as a TIFF file named saddle with a resolution of 200 dpi, one enters the following command: >> print -dtiff -r200 saddle.tiff Example To export Figure No. 2 to file spline2d.eps with resolution 600-dpi and using the EPS color graphics format, one types: >> print -f2 -r600 -depsc spline2d Note: The print command provides more flexibility in the type of output sent to the printer and permits one to control printing from M-files. The result can be sent directly to the default printer or stored in a specified file. A wide variety of graphics formats are supported, such as BMP, EPS, JPG, and TIF files. C. Exporting figures The basic options are featured for exporting a figure in a selected graphics format to a file for another application, such as a word processor. Using Export Setup GUI This option permits one to adjust or set the graphic characteristics, such as text size, font, and style. Figures can be saved using various standard graphics file formats such as BMP, EPS, JPG, and TIF. The following select-click sequence opens the Export Setup GUI from the MATLAB figure window: >> File >> Export Setup This GUI has four dialog boxes that enable one to: 1. 2. 3. 4. Adjust the figure size Change the rendering Change font characteristics Change line characteristics 429 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab After the figure properties have been changed or adjusted, one can follow the standard Windows GUI procedure to export the figure. Using MATLAB commands This option is simply printing a figure to a file using MATLAB commands as described in the previous section. Using Windows clipboard To copy the figure in the current active figure window to Windows clipboard, one simply applies the following select-click sequence: >> Edit >> Copy Figure The figure written to the clipboard has either of the two graphics file formats: EMF color vector or BMP 8-bit color bitmap. MATLAB selects the format automatically. One may choose to adjust the figure settings or change the default graphics format before writing the figure to the clipboard. This will require the use of the Copy Options Preferences dialog box, which is opened with the following select-click sequence: >> Edit >> Copy Options 430 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab 4.7 In-lab Experiments This experiment consists of a series of MATLAB exercises. All the data created and resulted from all the experiment exercises should be saved in your USB flash drive. By doing so you can extract the data needed to write the lab report following the in-lab session. Experiment 4.1 (a) Make use of the MATLAB function sinc to create a 2-D line graph of good resolution defined by 𝑦 sin 𝜋𝑥 𝜋𝑥 𝑠𝑖𝑛𝑐 𝑥 for 10 𝑥 10 (b) Enter the edit-plot mode, then do the following to enhance the graph: (1) Label the x-axis with ‘x’ and the y-axis with ‘y = sinc(x)’. (2) Change the default line width from 0.5 point to 2 point. (3) Add grid lines to the graph. (c) Export the enhanced figure as a JPEG file with filename ‘Group_n_L4_1’, where n is the number assigned to your lab station. Experiment 4.2 (a) In a single figure plot three 2-D line graphs of good resolution defined, respectively, as follows: 𝑓 𝑡 5𝑡 ∙ exp 𝑓 𝑡 5 𝑡 1.5 ∙ exp 𝑓 𝑡 5 𝑡 3.5 ∙ exp 𝑡 5 𝑡 𝑡 1.5 5 3.5 5 where 0 𝑡 10. (b) Enter the edit-plot mode and adjust or add the following attributes to enhance the figure: (1) Label the x-axis with ‘t’. (2) Change the default line style for f2(t) to ‘dash_dot’, and the default line style for f3(t) to ‘dashed’. (3) Add a legend to the figure using labels ‘f1(t)’, ‘f2(t)’, and ‘f3(t)’. (c) Export the enhanced figure as an EPS file having the filename ‘Group_n_L4_2’, where n is the number assigned to your lab station. 431 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab Experiment 4.3 (a) Create seven data sequences n, h, H, t1, x, t2, and y using the following command sequence >> >> >> >> >> n = [0 : 15]; h = [zeros(1, 4), 0.75*ones(1, 8), zeros(1, 4)]; H0 = fft(h); H = fftshift(H0); t1 = [0 : 10]; x = 0.75*exp(-0.2*t1); t2 = [0 : 25]; y = conv(h, x); (b) Create the bar graphs for the data pairs (n, h), (n, H), (t1, x), and (t2, y) using the stem function and plot them in a single figure as subplots identified with position indices 1, 2, 3, and 4, respectively. (c) Export the enhanced figure as an EPS file with filename ‘Group_n_L4_3’, where n is the number assigned to your lab station. Experiment 4.4 (a) Create a 3-D line graph with good resolution for a conical helix whose coordinates are defined by following parametric equations: 𝑥 𝑡 ⋅ 𝑠𝑖𝑛 𝑡 , 𝑦 𝑡 ⋅ 𝑐𝑜𝑠 𝑡 , 𝑧 𝑡 for 0 𝑡 10𝜋 (b) Without entering the edit-plot mode, use MATLAB commands to adjust or add the following attributes to the graph: (1) Label the x-axis, y-axis, and z-axis with ‘x(t)’, ‘y(t)’, and ‘z(t)’, respectively. (2) Change the default line width from 0.5 point to 2 point. (3) Add the title ‘Conical Helix’. (4) Add grid lines. (c) Export the enhanced figure as a bitmap file with filename ‘Group_n_L4_4’, where n is the number assigned to your lab station. 432 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab Experiment 4.5 (a) Consider a surface z(x, y) defined as follows: 𝑧 𝑥, 𝑦 𝑠𝑖𝑛𝑐 𝑅 sin 𝜋𝑅 , 𝑅 𝜋𝑅 𝑥 𝑦 , 3 𝑥. 𝑦 3 Make use of the MATLAB functions sinc and mesh to generate a surface plot of z(x, y). Label the x-axis, y-axis, and z-axis with ‘x’, ‘y’, and ‘z(x, y)’, respectively. Export the figure as a JPEG file with filename ‘Group_n_L4_5a’, where n is the number assigned to your lab station. (Note: The sinc function is defined in Experiment 4.1.) (b) Repeat part (a), but add the following string to the argument list of the mesh function: 'EdgeColor', 'black' Use the filename ‘Group_n_L4_5b’ instead for the exported figure. (c) Repeat part (a), but use the 3-D plot function surf instead plus two additional instructions given below: >> colormap hsv, >> colorbar Use the filename ‘Group_n_L4_5c’ instead for the exported figure. (d) Repeat part (a), but use the 3-D plot function surf instead and include the following string in its argument list: 'FaceColor', 'red', 'EdgeColor', 'none' Examine the attribute of the figure. Add the following instructions sequentially afterward and observe their effects on the figure. >> camlight left >> lighting phong Use the filename ‘Group_n_L4_5d’ instead for the exported figure. 433 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab Experiment 4.6 The total spending in USA in a recent fiscal year is tabulated below: Interest on Debt Medicare & Health Military SS, Labor & Unemployment Others 6.5% 25% 21.5% 35% 12% (a) Create a pie chart that illustrates the total spending for fiscal year 2013 proposed by the US President. (b) Repeat part (a) with the largest slice in the pie drawn with an offset. (c) Export the figures created in parts (a) and (b) as JPEG files with filenames ‘Group_n_L4_6a’ and ‘Group_n_L4_6b’, respectively. Note n is the number assigned to your lab station. Experiment 4.7 MATLAB is equipped with two functions for generating random numbers that follow the uniform distribution and the normal (Gaussian) distribution. These functions are rand and randn, respectively. (a) Use the help command to enable you to write a concise description of the rand function. Then create a 10-bin histogram of 100 random numbers generated by the rand function. (b) Use the help command to enable you to write a concise description of the randn function. Then create a 20-bin histogram of 500 random numbers generated by the randn function. Use the range [-5, 5] for the histogram. (c) Export the figures created in parts (a) and (b) as PNG files with filenames ‘Group_n_L4_7a’ and ‘Group_n_L4_7b’, respectively. Note n is the number assigned to your lab station. 434 Spring 2024 Professor B.W. Kwan EEL3002L Lab #4 ECE Tools Lab Experiment 4.8 The capacitor voltage vC (t ) of a transient RC circuit is given by: 𝑣 𝑡 1.5 5, 3.5𝑒 . 𝑡 , 𝑡 0 0 (a) Sample the capacitor voltage vC (t ) using uniform sampling interval of 0.2 second over the time interval [-2, 5]. Store the sample points in the array v_c. (b) Plot v_c as a staircase function of time. Label the axes properly. (c) Export the figure created in part (b) as an EPS file with filename ‘Group_n_L4_8’. Note n is the number assigned to your lab station. 4.8 Lab Report Document the experimental results using the format based on the lab report template. References [1] MATLAB documents and resources available at the MathWorks, Inc. website: www.mathworks.com [2] Textbook for EEL3111 and EEL3112 OR the textbook for EEL3003. 435 Spring 2024 Professor B.W. Kwan