MATLAB Learning notes 4:3-dimensional drawing

Source: Internet
Author: User
Tags cos explode in degrees rand sin

76.

>> x=[0 0 0];y=[30 90];z=[0 0 0];% draw a straight line on the plane z=0
PLOT3 (x, Y, z)
On
>> grid on
>> x1=[0 0 0 0];y1=[0 36];z1=[3 3 3 3];% draw a straight line on the plane z=3
PLOT3 (X1,Y1,Z1)
Grid on
On
>> x2=[0 0 0 0];y2=[0 0];z2=[0 0 1 1];% draw an unclosed rectangle
PLOT3 (X2,Y2,Z2)
On
>> x2=[0 0 0 0 0];y2=[0 0 0];z2=[0 0 1 1 0];% draw enclosing Rectangle
PLOT3 (X2,Y2,Z2)

77. Three-dimensional pie chart
X=[32 45 11 76 56];
Explode=[0 0 1 0 1];%1 means separate.
Pie3 (X,explode)

PLOT3 drawing three-dimensional graphs
X=-5:0.4:5;
y=5:-0.4:-5;
Z=exp ( -0.2*x). *cos (y);
[X,y]=meshgrid (x, y);
Z=exp ( -0.2*x). *cos (Y);
Figure
Subplot (2,1,1)
PLOT3 (x, y, Z, ' or ', x, Y, z)
Subplot (2,1,2)
PLOT3 (x, Y, z)

79. Setting the angle of view
Subplot (2,2,1)
Ezmesh (@peaks);
View (3);
[A,b]=view;title (Mat2str ([b]))%-37.5 30
Subplot (2,2,2)
Ezmesh (@peaks);
View (2);
[A,b]=view;title (Mat2str ([b]))%0 90
Subplot (2,2,3)
Ezmesh (@peaks);
View ([30 45]);
[A,b]=view;title (Mat2str ([b]))%30 45
Subplot (2,2,4)
Ezmesh (@peaks);
View ([1 1 sqrt (2)]);
[A,b]=view;title (Mat2str ([b]))%135 45

>> Help View
VIEW Specification Graph viewpoint.
View (Az,el) and view ([Az,el]) set the angle of the view from which an
Observer sees the current. AZ is the azimuth or horizontal
Rotation and EL are the vertical elevation (both in degrees). Azimuth
Revolves about the z-axis, with positive values indicating counter-
Clockwise rotation of the viewpoint. Positive values of elevation
correspond to moving above the object; Negative values move below.
View ([X Y Z]) sets the view angle in Cartesian coordinates. The
magnitude of Vector x, y, Z is ignored.

Here is some examples:

AZ = -37.5, EL = is the default-Z view.
AZ = 0, EL = directly overhead and the default 2-d view.
AZ = EL = 0 looks directly up the first column of the Matrix.
AZ = is behind the matrix.

80. Create multiple tile Models
Subplot (1,2,1)
X=[0 0;0 1;0 1;0 0];
Y=[0 0;1 0;1 1;0 1];
Z=[0 0;0 0;1 0;1 0];
Patch (x, Y, Z, ' r ')% padding
View ([30,30])
Subplot (1,2,2)
Vm=[0 0 0;1 0 0;1 0 1;0 0 1;0 1 1;1 1 1;1 1 0];
Fm=[1 2 3 4;3 4 5 6;6 3 2 7];
Patch (' Vertices ', Vm, ' Faces ', Fm, ' Edgecolor ', ' r ')% draw edge
View ([30,30])

81. Create a tile model
Subplot (2,2,1)
X=[0 1 0.5];y=[0 0 1];
Fill (x, Y, ' R '), title (' Fill ')
Subplot (2,2,2)
X=[0 0 0 0]; Y=[0 1 1 0]; Z=[0 0 1 1];
Fill3 (x, y, Z, ' G '); title (' Fill3 ')
Subplot (2,2,3)
Patch (x, Y, z, ' B '); View ([30,30])
Title (' Patch:high-level syntax ')
Subplot (2,2,4)
Patch (' XData ', X, ' Ydata ', Y, ' Zdata ', Z); view ([30,30])
Title (' Patch:low-level syntax ')

82. Non-grid data point plotting
X=rand (1,20);
Y=rand (1,20);
Z=cos (0.5.*x). *sin (y);
Xi=linspace (0,1,50);
Yi=linspace (0,1,50);
[X,y]=meshgrid (Xi,yi);
Subplot (2,2,1)
Z1=griddata (x,y,z,x,y, ' linear ');
Mesh (X,Y,Z1)
Title (' Linear ')
Subplot (2,2,2)
Z1=griddata (x,y,z,x,y, ' nearest ');
Mesh (X,Y,Z1)
Title (' Nearest ')
Subplot (2,2,3)
Z1=griddata (x,y,z,x,y, ' cubic ');
Mesh (X,Y,Z1)
Title (' Cubic ')
Subplot (2,2,4)
Z1=griddata (x,y,z,x,y, ' V4 ');
Mesh (X,Y,Z1)
Title (' v4 ')

83. Simple three-dimensional drawing function
Subplot (2,2,1)
Ezplot3 (' sin (t) ', ' cos (t) ', ' Sin (2*t) ', [0,2*pi])
Subplot (2,2,2)
Ezmesh (@peaks, [-5 5-5 5])
Subplot (2,2,3)
Ezsurf (@ (x, y) (x.^2+y.^2), [-5 5-5 5])
Subplot (2,2,4)
EZSURFC (@ (x, y) (x.^2+y.^2), [-5 5-5 5])

84. Rectangular Grid
X=-5:0.5:5;
y=5:-0.5:-5;
[X,y]=meshgrid (x, y);
Whos
Plot (x, y, ' o ')

85. Three-dimensional surface diagram
Close all
Clear
[x, Y] = Meshgrid ( -3:.5:3);
Z = 2*x.^2-3*y.^2;
Subplot (2,2,1)
Mesh (x, y, z)
Title (' Mesh ')
Subplot (2,2,2)
Surf (x, y, z)
Title (' Surf ')
Subplot (2,2,3)
SURFC (x, Y, z)
Title (' Surfc ')
Subplot (2,2,4)
SURFL (x, Y, z)
Title (' SURFL ')

86. Three-dimensional contour map
Clear
Close all
[X,y]=meshgrid ( -3:0.01:3);
z=x.^2+y.^2;
CONTOUR3 (x,y,z,20)
View ([45 50])

87. Three-dimensional match rod diagram stem3
Clear
X=rand (1,10);
Y=rand (1,10);
Z=x.^2+2*y;
Stem3 (x, y, Z, ' Fill ')

88. Three-dimensional scatter plot
Close all
Clear
X=rand (1,10);
Y=rand (1,10);
z=x.^2+y.^2;
Scatter3 (x, y, Z, ' ro ')
On
[X,y]=meshgrid (0:0.1:1);
z=x.^2+y.^2;
Mesh (x, y, z)
Hidden off

89. Three-dimensional Network diagram
Close all
Clear
[x, Y] = Meshgrid ( -3:.5:3);
Z = 2*x.^2-3*y.^2;
Subplot (2,2,1)
PLOT3 (x, Y, z)
Title (' Plot3 ')
Subplot (2,2,2)
Mesh (x, y, z)
Title (' Mesh ')
Subplot (2,2,3)
MESHC (x, Y, z)
Title (' MESHC ')
Subplot (2,2,4)
Meshz (x, Y, z)
Title (' Meshz ')

90. Three-dimensional vector field diagram
Clear
Close all
[X,y]=meshgrid ( -3:0.4:3);
z=-3*x.^2-y.^2;
[U,v,w]=surfnorm (x, y, z);
Quiver3 (x,y,z,u,v,w,0.2)
On
Surf (x, y, z)

91. Three-dimensional bar chart
Clear
X=rand (3,10);
Subplot (2,2,1)
Bar (x)
Title (' Bar ')
Subplot (2,2,2)
Barh (x, ' stack ')
Title (' Barh-stack ')
Subplot (2,2,3)
BAR3 (x)
Title (' Bar3 ')
Subplot (2,2,4)
BAR3H (x, ' stack ')
Title (' Bar3h-stack ')

92. Set the color of multiple block models
Clear
Close all
Vm=[0 0 0;1 0 0;1 0 1;0 0 1;0 1 1;1 1 1;1 1 0];
Fm=[1 2 3 4;3 4 5 6;6 3 2 7];
Subplot (3,2,1)
Patch (' Vertices ', Vm, ' Faces ', Fm, ' Facevertexcdata ', rand (), ' facecolor ', ' flat ')
View ([30,30]); title (' Set Uniform Index-color ')
Subplot (3,2,2)
Patch (' Vertices ', Vm, ' Faces ', Fm, ' Facevertexcdata ', rand (1,3), ' facecolor ', ' flat ')
View ([30,30]); title (' Set Uniform Rgb-color ')
Subplot (3,2,3)
Patch (' Vertices ', Vm, ' Faces ', Fm, ' Facevertexcdata ', rand (Size (vm,1), 1), ' Facecolor ', ' interp ')
View ([30,30]); Title (' Assign Multi-index-color to Vertices ')
Subplot (3,2,4)
Patch (' Vertices ', Vm, ' Faces ', Fm, ' Facevertexcdata ', rand (Size (vm,1), 3), ' Facecolor ', ' interp ')
View ([30,30]); Title (' Assign Multi-rgb-color to Vertices ')
Subplot (3,2,5)
Patch (' Vertices ', Vm, ' Faces ', Fm, ' Facevertexcdata ', rand (Size (fm,1), 1), ' facecolor ', ' flat ')
View ([30,30]); Title (' Assign Multi-index-color to Faces ')
Subplot (3,2,6)
Patch (' Vertices ', Vm, ' Faces ', Fm, ' Facevertexcdata ', rand (Size (fm,1), 3), ' Facecolor ', ' flat ')
View ([30,30]); Title (' Assign Multi-rgb-color to Faces ')

93. Setting axes
Close all
Subplot (1,3,1)
Ezsurf (@ (t,s) (sin (t). *cos (s)), @ (t,s) (sin (t). *sin (s)), @ (t,s) cos (t), [0,2*PI,0,2*PI])
Axis auto;title (' auto ')

Subplot (1,3,2)
Ezsurf (@ (t,s) (sin (t). *cos (s)), @ (t,s) (sin (t). *sin (s)), @ (t,s) cos (t), [0,2*PI,0,2*PI])
Axis equal;title (' equal ')

Subplot (1,3,3)
Ezsurf (@ (t,s) (sin (t). *cos (s)), @ (t,s) (sin (t). *sin (s)), @ (t,s) cos (t), [0,2*PI,0,2*PI])
Axis square;title (' square ')

94. Grid Border Line settings
Close all
Clear
[x, Y] = Meshgrid ( -3:.25:3);
Z =-sqrt (x.^2+3*y.^2);
Subplot (1,2,1)
Mesh (x, y, z)
Hidden on
Title (' Hidden on ')
Subplot (1,2,2)
Mesh (x, y, z)
Hidden off
Title (' Hidden Off ')

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.