当前位置:网站首页>Drawing curve with MATLAB

Drawing curve with MATLAB

2022-06-10 10:23:00 Prosperity is like love

draw a curve

plot(x,y):x and y For vectors of the same length , They are used to store x Coordinates and y coordinate 
plot(x1,y1, Options 1,x2,y2, Options 2...): Multiple groups of polylines 
plot3(x1,y1,z1, Options 1,xn,yn,zn, Options n) : The space curve 
fplot('fun',[a,b]): draw fun The function is in the interval [a,b] Graphics on ,fun It can be a function or an expression 

% The above options can be
% Linetype - Solid line : Dotted line -. Point line -- Underline
% Dot the mark . spot o circle x fork + plus * asterisk s square d The diamond
% ^ Upward triangle v Down > To the right < Left triangle p Pentagonal h hexagon
% Color b Blue ( Default ) m Brown c Cyan r Red g green y yellow w white k black

% example
x = 0:pi/100:2pi;
y = 2
exp(-0.5x).sin(2pix);
plot(x,y,‘ro’); % among ’r*' Is the above option
![ Insert picture description here ](https://img-blog.csdnimg.cn/642d2a4108064ab0a804804a81aec86d.png

% use fplot function
fplot(@(x)2exp(-0.5x)sin(2pix),[0,2pi],‘gd’);

% Three dimensional drawing
t =0:pi/50:2pi;
x = 8
cos(t); y = 4*sqrt(2)sin(t);
z = -4
sqrt(2)*sin(t);
plot3(x,y,z,‘sk’);

% Surface graphics
% Generation of plane grid coordinates
x =a:dx:b;
y = c:dy:d;
[X,Y] = meshgrid(x,y);
% Functions for drawing 3D surfaces
% mesh(x,y,z): Grid ;
% surf(x,y,z) : Surface graph ( Fill the mesh );
% contour(x,y,z): Contour map ( plan );
% contour3(x,y,z): Three dimensional contour map ( Spatial map );

% example
figure
xa=-2:0.2:2; ya = xa;
[x,y]=meshgrid(xa,ya);
z = x.*exp(-x.2-y.2);
mesh(x,y,z) ; pause(2); % Grid
surf(x,y,z) ; pause(2); % Fill the mesh
contour(x,y,z) ; pause % Plane contour line
contour3(x,y,z) ; pause % Solid contour lines
contour(x,y,z,[-0.1 0.1]);
surf(x,y,z);

% Segmentation of graphics window subplot(m,n,p)
hold off % Release the graphics of the current graphics window
x = linspace(0,2pi,60);
y = sin(x);
z = cos(x);
subplot(2,2,1); %2 That's ok x2 In column 1 District No
plot(x,y); title(‘sin(x)’); axis([0,2
pi,-1,1]);
subplot(2,1,2); %2 That's ok 1 Zone 2 in the column
plot(x,z,'
'); title(‘cos(x)’); axis([0,2*pi,-1,1]);
x = linspace(-2,2,60);
y = x.^3;
subplot(2,2,2); %2 That's ok x2 In column 2 District No
plot(x,y); title(‘x^3’); axis([-2,2,-4,4]);

% Graphic labels
% title( Graphic name ) xlabel(x Axis description ) ylabel(y Axis description )
% Loop statement
hold on /off % Retain / Release existing drawings
figure / close % The opening of new / Close the graphics window
grid on /off % draw / No gridlines , No parameters grif The command switches between the two states
axis on /off % Show / Cancel axis
axis([xmin xmax ymin ymax zmin zmax]) % Limit the range of the coordinate axis

原网站

版权声明
本文为[Prosperity is like love]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206100952467313.html