Matlab Graphics
description
Transcript of Matlab Graphics
![Page 1: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/1.jpg)
Matlab Graphics
S. Awad, Ph.D.M. Corless, M.S.E.E.E.C.E. DepartmentUniversity of Michigan-Dearborn
Introduction to Matlab:
3D Graphics
![Page 2: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/2.jpg)
2
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
3D Graphics Topics Creating Mesh and Surface Plots Viewing a Pseudocolor Matrix Creating Contour Plots Adding a Color-Bar Interpolating 3D Data
![Page 3: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/3.jpg)
3
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Mesh and Surface Plots
Given a function f(x,y) of two variables:
22
),( yxexyxf
Assume that:» x=[-1:0.2:1]; y=[-1:0.2:1];
We can plot the function z as a mesh or surface plot
)( 22
),( yxxeyxfz
Useful for displaying functions of 2 variables or to visualize large matrices
![Page 4: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/4.jpg)
4
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Calculating xx
Height = Length of y
15.005.01 x
Row = Vector x
15.005.01
11111
xx
15.0005.115.0005.115.0005.115.0005.115.0005.1
![Page 5: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/5.jpg)
5
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Generating xx in Matlab» x=[-1:0.5:1];» xx=ones(length(x),1)*x
xx =
-1.0000 -0.5000 0 0.5000 1.0000 -1.0000 -0.5000 0 0.5000 1.0000 -1.0000 -0.5000 0 0.5000 1.0000 -1.0000 -0.5000 0 0.5000 1.0000 -1.0000 -0.5000 0 0.5000 1.0000
![Page 6: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/6.jpg)
6
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Calculating yy
Length = Length of y
15.005.01 y
11111
15.005.01
yy
111115.05.05.05.05.0000005.05.05.05.05.011111
Column = y Transpose
![Page 7: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/7.jpg)
7
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Generating yy in Matlab» y=[-1:0.5:1];» yy=y'*ones(1,length(y))
yy =
-1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -0.5000 -0.5000 -0.5000 -0.5000 -0.5000 0 0 0 0 0 0.5000 0.5000 0.5000 0.5000 0.5000 1.0000 1.0000 1.0000 1.0000 1.0000
![Page 8: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/8.jpg)
8
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Find xx & yy Using Meshgrid» [xx,yy] = meshgrid(x,y)xx = -1.0000 -0.5000 0 0.5000 1.0000 -1.0000 -0.5000 0 0.5000 1.0000 -1.0000 -0.5000 0 0.5000 1.0000 -1.0000 -0.5000 0 0.5000 1.0000 -1.0000 -0.5000 0 0.5000 1.0000yy = -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -0.5000 -0.5000 -0.5000 -0.5000 -0.5000 0 0 0 0 0 0.5000 0.5000 0.5000 0.5000 0.5000 1.0000 1.0000 1.0000 1.0000 1.0000
![Page 9: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/9.jpg)
9
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Find z Find z using element by element computations
» z=xx.*exp(-xx.^2-yy.^2)
z =
-0.1353 -0.1433 0 0.1433 0.1353 -0.2865 -0.3033 0 0.3033 0.2865 -0.3679 -0.3894 0 0.3894 0.3679 -0.2865 -0.3033 0 0.3033 0.2865 -0.1353 -0.1433 0 0.1433 0.1353
![Page 10: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/10.jpg)
10
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Mesh Plot z» mesh(x,y,z)
Finer increments of x and y will smooth the surface
![Page 11: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/11.jpg)
11
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Create a new mesh plotcomplete with labels
Mesh for a Larger x & y
» x =[-2:0.2:2];» y =[-2:0.2:2];» [xx,yy]=meshgrid(x,y);» z=xx.*exp(-xx.^2-yy.^2);» mesh(x,y,z)» title('Larger Mesh');» xlabel('X Data');» ylabel('Y Data');» zlabel('z=xx.*exp(-xx.^2-yy.^2)');
![Page 12: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/12.jpg)
12
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Plots the colored parametric surface where color is proportional to surface height
Surface Plot of z» surf(x,y,z)
![Page 13: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/13.jpg)
13
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
The values of the elements specify the color in each cell of the plot
pseudocolor or "checkerboard" plot of matrix
Pcolor» pcolor(x,y,z)
![Page 14: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/14.jpg)
14
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Contour Plots contour plot of
matrix where z contains heights above a plane
Number of Contour Lines
» contour(x,y,z,16);» title('Contour');
![Page 15: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/15.jpg)
15
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Displaying Contour Heights To write the values
identifying the heights:
» cs=contour(x,y,z,16);» clabel(cs);» title('Contour Heights');
![Page 16: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/16.jpg)
16
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Meshc Contour Plots meshc is same as
mesh except that a contour plot is drawn beneath the mesh
Only works for surfaces defined on a rectangular grid
» meshc(x,y,z)
![Page 17: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/17.jpg)
17
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Adding a Colorbar
colorbar adds a vertical line (color scale) to show the contour plots
![Page 18: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/18.jpg)
18
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
3D Interpolation Rough or scattered data can be interpolated using mesh
The original data is plotted as a mesh by:
» x=[-3:3]; y=[1:5];» [xx, yy]=meshgrid(x,y);» z= xx + yy;» mesh(x,y,z);» title('Original Mesh Grid');» xlabel('X Data'); ylabel('y Data');» zlabel('z = xx + yy');
![Page 19: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/19.jpg)
19
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Mesh of Rough Data Original Course Surface where:
x = [-3:3]y = [1:5]z = xx+yy
![Page 20: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/20.jpg)
20
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
Interpolation of Data The original mesh from the data is can be improved by
creating interpolated values using griddata:
» xi=[-3:0.5:4]; % Interpolated x axis» yi=[ 0:0.2:5]; % Interpolated y axis» [xxi,yyi]=meshgrid(xi,yi);» % zi = interpolated values» zi=griddata(xx,yy,z,xxi,yyi);» mesh(xxi,yyi,zi); % Better surface» title('Interpolated Mesh Grid');» xlabel('X Data'); ylabel('y Data');» zlabel('z = xx + yy');
![Page 21: Matlab Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062310/56815cb0550346895dcab02e/html5/thumbnails/21.jpg)
21
MATLAB Graphics:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
3D Graphics
3D Interpolation Plot Interpolated Smooth Surface where:
xi = [-3:0.5:4] yi = [ 0:0.2:5]