MATLAB绘图及例子总结

二维图

例 1

X1=[1,2,4,6,7,8,10,11,12,14,16,17,18,20];
Y1=[1,2,4,6,7,8,10,10,8,7,6,4,2,1];
figure(1)
plot(X1,Y1,'o','MarkerSize',15)
X2=1:20;
Y2=log(X2);
figure(2)
plot(X2,Y2,'o','MarkerSize',15)

结果:

例 2

X1=(0:12)*pi/6;
Y1=cos(3*X1);
X2=(0:360)*pi/180;
Y2=cos(3*X2);
figure(1)
subplot(2,2,1);
plot(X1,Y1,'o','MarkerSize',3); % 设置标准尺寸为3
xlim([0 2*pi]) % 补充知识点xlim
% x轴上下限设定xlim([a,b]);
% y轴上下限设定ylim([a,b])
subplot(2,2,2);
plot(X1,Y1,'LineWidth',2); % 设置线宽度为2
xlim([0 2*pi])
subplot(2,2,3);
plot(X2,Y2,'o','MarkerSize',3);
xlim([0 2*pi])
subplot(2,2,4);
plot(X2,Y2,'LineWidth',2);
xlim([0 2*pi])

结果:

例 3

x=-pi/2:0.01:pi/2;
y=x+sin(x)+exp(x);
plot(x,y,'-ro'); % 颜色红色
grid on % 网格
title('y的函数图像');
xlabel('x');
ylabel('y');
legend('y=x+sinx+e^(x)');

结果:

例 4

A=magic(20);
A(9:20,:)=[];
figure(1);
plot(A);
for i=1:5
for j=1:6
B(i,j)=i+j;
end
end
x=0.2:0.2:1;
figure(2)
subplot(2,2,1);plot(B,x,'LineWidth',1.5);
subplot(2,2,2);plot(x,B,'LineWidth',1.5);
C=reshape(1:30,5,6); % 变换成特定维数5×6的矩阵
subplot(2,2,3);plot(B,C,'LineWidth',1.5);
subplot(2,2,4);plot(C,B,'LineWidth',1.5);

结果:



例 5

x=-pi:pi/10:pi;
y=tan(sin(x))-sin(tan(x));
plot(x,y,'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10);
% MarkerFaceColor:点符号填充颜色
% MarkerEdgeColor:点边框颜色

结果:

例 6

clear all
x=-pi:pi/10:pi;
y=[sin(x);sin(x+3);sin(x+5)];
z=[cos(x);cos(x+3);cos(x+5)];
figure;
plot(x,y,'r:*',x,z,'g-.v');
% r是红色,:是点线,*是星号标记
% g是绿色,-.是点画线,v是倒三角形

结果:

例 7

% 绘制双坐标轴
figure
angl=0:0.01*pi:2*pi;
ampl=sin(0:0.01*pi:2*pi);
z=ampl.*(cos(angl)+sqrt(-1)*sin(angl));
[AX,H1,H2]=plotyy(0:200,abs(z),0:200,angle(z)*180/pi);
% angle用来求复数矩阵相位角的弧度值,其取值为-pi到pi,z是一个复数,abs(z)是复数的模
set(get(AX(1),'Ylabel'),'String','amplitude') % amplitude振幅
set(get(AX(2),'Ylabel'),'String','phase') % phase阶段
% get返回某些对象属性的当前值
set(H1,'LineWidth',3);
set(H2,'LineStyle',':','LineWidth',3)

结果:

例 8

% x轴对数坐标
x=10.^(0.1:0.1:4);
y=1./(x+1000);
figure
subplot(1,2,1);
semilogx(x,y,'+','MarkerSize',5,'LineWidth',2);
title('y=(x+1000)^{-1}')
subplot(1,2,2);
plot(x,y,'+','MarkerSize',5,'LineWidth',2);
title('y=(x+1000)^{-1}')
% y轴对数坐标同理

结果1:

% x轴和y轴均为对数坐标
a=0.1:0.1:5;
x=log10(a);
y=10.^a;
figure
subplot(1,2,1)
loglog(x,y,'+','MarkerSize',5,'LineWidth',2)
title('lgy=10^x')
subplot(1,2,2)
plot(x,y,'+','MarkerSize',5,'LineWidth',2)
title('lgy=10^x')

结果2:

例 9

y=[75.995,91.972,105.711,123.203,131.669...
150.697,179.323,203.212,226.505,249.633,281.422];
figure;
bar(y);

结果:

例 10

x=-2:2;
Y=[6,8,7,4,5;4,8,1,12,0;4,6,21,1,3];
subplot(1,2,1),bar(x',Y','stacked')
xlabel('x'),ylabel('\Sigma y'),colormap(cool)
legend('因素 1','因素 2','因素 3')
subplot(1,2,2),barh(x',Y','grouped') % barh创建水平直方图
xlabel('y'),ylabel('x')

结果:

例 11

x=[1,5,0.5,3.5,2];
explode=[0,1,0,0,0];
pie(x,explode) % 饼图
colormap jet
figure
pie3(x,explode)
colormap hsv

结果:

例 12

x=-4:0.1:4;
y=randn(5000,1);
hist(y,x) % 直方图

结果:

例 13

clear
figure;
x=[1,5,6,7,9,5,1,3,12,20];
y=[20,15,6,3,1,5,3,0,1,5];
subplot(121);
scatter(x,y); % 散点图
subplot(122);
scatter(x,y,[],[1,0,0],'fill');

结果:

三维图

例 1

theta=0:0.01*pi:2*pi;
x=sin(theta);
y=cos(theta);
z=cos(4*theta);
figure
plot3(x,y,z,'LineWidth',2);hold on;
theta=0:0.02*pi:2*pi;
x=sin(theta);
y=cos(theta);
z=cos(4*theta);
plot3(x,y,z,'rd','MarkerSize',10,'LineWidth',2)

结果:

例 2

X=-10:0.1:10;
Y=-10:0.1:10;
[X,Y]=meshgrid(X,Y);
Z=-X.^2-Y.^2+200;
mesh(X,Y,Z)

结果:

例 3

figure
surf(X,Y,Z,'FaceColor','red','EdgeColor','none');
camlight left; % 左侧加一个发光物体
lighting phong % 光照模式,使图表面光滑细腻,色彩丰富
view(-15,65) % 视角的角度

结果:

例 4

···

[X,Y,Z]=peaks(30); %peaks函数是一个典型的多元函数,本质上是一个二元高斯分布的概率密度函数

subplot(1,2,1);surfl(X,Y,Z),colormap(copper),title('Default Lighting'),shading interp

subplot(1,2,2);surfl(X,Y,Z,[-90,30],[.55,.6,2,10]),shading interp

···

结果:

例 5

% 等高线图
[X,Y,Z]=peaks(30);
figure
subplot(2,2,1);contour(X,Y,Z);axis square
subplot(2,2,2);contour(X,Y,Z,10);axis square
subplot(2,2,3);contour(X,Y,Z,-10:1:10);axis square
subplot(2,2,4);contour(X,Y,Z,':');axis square

结果:

例 6

[X,Y,Z]=peaks(30);
R=sqrt(X.^2+Y.^2);
subplot(1,2,1);
surf(X,Y,Z,Z);
axis tight
subplot(1,2,2);surf(X,Y,Z,R);
axis tight

结果:

MATLAB绘图及例子总结的更多相关文章

  1. Matlab绘图详解

    Matlab绘图 强大的绘图功能是Matlab的特点之一,Matlab提供了一系列的绘图函数,用户不需要过多的考虑绘图的细节,只需要给出一些基本参数就能得到所需图形,这类函数称为高层绘图函数.此外,M ...

  2. 使用axes函数在matlab绘图中实现图中图的绘制

    使用axes函数在matlab绘图中实现图中图的绘制 有时为了对细节进行详细说明,需要在一个较大坐标轴上绘制一个小图来对局部进行放大以阐述结果. 这可以通过调用axes函数实现. 下面通过绘制 y=1 ...

  3. matlab绘图--线性规划图解法示意

    matlab绘图--线性规划图解法示意 图解法 matlab绘图 区域填充 线性规划问题: matlab绘图 L1=[4,0;4,4];  plot(L1(:,1),L1(:,2));hold on  ...

  4. Matlab绘图(一二三维)

    Matlab绘图 强大的绘图功能是Matlab的特点之一,Matlab提供了一系列的绘图函数,用户不需要过多的考虑绘图的细节,只需要给出一些基本参数就能得到所需图形,这类函数称为高层绘图函数.此外,M ...

  5. Matlab绘图高级部分

    图形是呈现数据的一种直观方式,在用Matlab进行数据处理和计算后,我们一般都会以图形的形式将结果呈现出来.尤其在论文的撰写中,优雅的图形无疑会为文章加分.本篇文章非完全原创,我的工作就是把见到的Ma ...

  6. (转载)MatLab绘图

    转载自:http://www.cnblogs.com/hxsyl/archive/2012/10/10/2718380.html 转载自:http://www.cnblogs.com/jeromebl ...

  7. Matlab绘图系列之高级绘图

    Matlab绘图系列之高级绘图 原帖地址: http://blog.163.com/enjoy_world/blog/static/115033832007865616218/ Matlab绘图 20 ...

  8. matlab绘图(详细)(全面)

    Matlab绘图 强大的绘图功能是Matlab的特点之一,Matlab提供了一系列的绘图函数,用户不需要过多的考虑绘图的细节,只需要给出一些基本参数就能得到所需图形,这类函数称为高层绘图函数.此外,M ...

  9. Matlab 绘图完整入门

    Matlab绘图 强大的绘图功能是Matlab的特点之一,Matlab提供了一系列的绘图函数,用户不需要过多的考虑绘图的细节,只需要给出一些基本参数就能得到所需图形,这类函数称为高层绘图函数.此外,M ...

随机推荐

  1. Oracle自动化安装脚本-part01-亲试ok

      #!/bin/bash   node_num=$1 base_config=./network.conf   网络配置文件 software_config=./software.conf  软件包 ...

  2. Property or method "openPageOffice" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by

    Property or method "openPageOffice" is not defined on the instance but referenced during r ...

  3. mysql 1040 连接数太多 mysql Error 1040 too many connection解决办法

    近在用SpringMVC开发的时候,突然出现1040 too many connection的错误,看错误的意思是连接的人数太多了.百度经验:jingyan.baidu.com 方法/步骤   1 当 ...

  4. Windows服务启动时候报错1053

    用.net 开发了一个C#语言的windows服务,在本地和测试环境,安装启动都正常,在新的线上环境报错,不能启动-报出-错误1053:服务没有及时响应启动或控制请求. 后来发现时线上.NET FRA ...

  5. 关于npm audit fix

    https://blog.csdn.net/weixin_40817115/article/details/81007774 npm audit : npm@5.10.0 & npm@6,允许 ...

  6. leetcode解题报告(3):Search in Rotated Sorted Array

    描述 Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 m ...

  7. CSP-S 模拟测试92 题解

    话说我怎么觉得我没咕多长时间啊,怎么就又落了20多场题解啊 T1 array: 根据题意不难列出二元一次方程,于是可以用exgcd求解,然而还有一个限制条件就是$abs(x)+abs(y)$最小,这好 ...

  8. Selenium中使用Cookies绕过登录

    在使用selenium测试后台时常常每个流程都需要走登录流程,这样自然比较浪费时间.如果遇到登录需要输入验证码等情况,就可能出师未捷身先死. 在Web应用中,登录状态通常是通过Cookie中对应的se ...

  9. MySQL数据分析—(4)关系数据库的三个逻辑框架

    (一)前面课程逻辑梳理 任何一门数据的软件也好,数据构架也好,或者说是数据学科也好,最终都是要解决实际问题的,大家说是不是? 前面jacky讲为什么要引入数据库的时候,举了一个案例,大家还记的吗?大家 ...

  10. Git入门(待更)

    github是什么? 以下截取自百度百科 github: GitHub 是一个面向开源及私有软件项目的托管平台,因为只支持 Git 作为唯一的版本库格式进行托管,故名 GitHub. GitHub 于 ...