MATLAB画图指南---bilibili教学

bilibili地址:

https://www.bilibili.com/video/av9810059?from=search&seid=8719190082089703237

Matlab入门教程07

任务一:画二次曲线,三次曲线

>> x=-3:0.1:3;
>> y1=x.^2;
>> y2=x.^3;
>> axis equal 
>> plot(x,y1,'green-o',x,y2,'blue-o')

>> bar(y1)

任务二:三维图像螺旋线上升

>> theta=0:pi/50:6*pi;
>> x=cos(theta);
>> y=sin(theta);
>> plot(x,y)
>> z=0:300;
>> plot3(x,y,z)

俯视图

螺旋上升

最终希望达成目标,如下:

x = -5:0.1:5;
y=x.*x;
x2=-5:0.1:5;
y2=x2.^3;
>> plot(x,y)
>> hold on;
>> plot(x2,y2)
>> grid on;

>> title('x^2 vs x^3');
>> xlabel('x-axis');
>> ylabel('y-axis');

Matlab入门教程08

1

subplot(2,3,1)

x=-4:0.1:4;
y1=sin(x);
y2=sin(2.*x);
y3=sin(3.*x);
y4=sin(4.*x);

subplot(2,2,1);
plot(x,y1);
title('y=sin(x)');

subplot(2,2,2);
plot(x,y2);
title('y=sin(2x)');

subplot(2,2,3);
plot(x,y3);
title('y=sin(3x)');

subplot(2,2,4);
plot(x,y4);
title('y=sin(4x)');

x=-4:0.1:4;
y1=sin(x);
y2=sin(2.*x);
y3=sin(3.*x);
y4=sin(4.*x);

subplot(2,2,1);
plot(x,y1);
title('y=sin(x)');

subplot(2,2,2);
plot(x,y2);
title('y=sin(2x)');

subplot(2,2,[3,4]);
plot(x,y4);
title('y=sin(4x)');

1

曲线和曲面是不同的:

surf()函数

画抛物面

>> x=-3:1:3;
y=-3:1:3;
[X,Y] = meshgrid(x,y);
Z=X.^2 + Y.^2;
>> X

X =

    -3    -2    -1     0     1     2     3
    -3    -2    -1     0     1     2     3
    -3    -2    -1     0     1     2     3
    -3    -2    -1     0     1     2     3
    -3    -2    -1     0     1     2     3
    -3    -2    -1     0     1     2     3
    -3    -2    -1     0     1     2     3

>> Y

Y =

    -3    -3    -3    -3    -3    -3    -3
    -2    -2    -2    -2    -2    -2    -2
    -1    -1    -1    -1    -1    -1    -1
     0     0     0     0     0     0     0
     1     1     1     1     1     1     1
     2     2     2     2     2     2     2
     3     3     3     3     3     3     3

>> Z

Z =

    18    13    10     9    10    13    18
    13     8     5     4     5     8    13
    10     5     2     1     2     5    10
     9     4     1     0     1     4     9
    10     5     2     1     2     5    10
    13     8     5     4     5     8    13
    18    13    10     9    10    13    18


 
>> surf(X,Y,Z)

猜你喜欢

转载自blog.csdn.net/zjc910997316/article/details/88060471