尘中远

# Matlab绘图总结2

## 概述

``````clc;
clear all;
close all;
x = 0:0.01:5;
y1 = 2*sin(x)+0.1;
y2 = sin(x).*cos(x)+0.2;
y3 = sin(x)./(x+0.1);
y = [y1;y2;y3];
marker_style = {'>';'<';'s';'o';'d';'v';'p';'^';'*';'+';'x';'h'};
line_style = {'-';'--';':';'-.'};``````

## 如何在一个数据量很大的曲线上做标记

``````text_legend = {};
text_legend{1,1} = 'y1 = 2*sin(x)+0.1';
text_legend{2,1} = 'y2 = sin(x).*cos(x)+0.2';
text_legend{3,1} = 'y3 = sin(x)./(x+0.1)';
figure
set(gcf,'color','w');
hold on;
handle_plot = [];
handle_plot(1) = plot(x,y1,'-','color',[rand rand rand],'LineWidth',2);
handle_plot(2) = plot(x,y2,'-','color',[rand rand rand],'LineWidth',2);
handle_plot(3) = plot(x,y3,'-','color',[rand rand rand],'LineWidth',2);
grid on;
legend(handle_plot,text_legend,0);``````

``````figure
set(gcf,'color','w');
hold on;
handle_plot = [];
handle_plot(1) = plot(x,y1,'-<','color',[rand rand rand],'LineWidth',2);
handle_plot(2) = plot(x,y2,'-s','color',[rand rand rand],'LineWidth',2);
handle_plot(3) = plot(x,y3,'-o','color',[rand rand rand],'LineWidth',2);
grid on;
legend(handle_plot,text_legend,0);``````

``index = 1:50:length(x);``

``````figure
set(gcf,'color','w');
hold on;
handle_plot = [];handle_plot_Marker = [];
line_color = [rand rand rand];
handle_plot(1) = plot(x,y1,'-','color',line_color,'LineWidth',2);
handle_plot_Marker(1) = plot(x(index),y1(index),'<','color',line_color);
line_color = [rand rand rand];
handle_plot(2) = plot(x,y2,'-','color',line_color,'LineWidth',2);
handle_plot_Marker(2) = plot(x(index),y2(index),'s','color',line_color);
line_color = [rand rand rand];
handle_plot(3) = plot(x,y3,'-','color',line_color,'LineWidth',2);
handle_plot_Marker(3) = plot(x(index),y3(index),'o','color',line_color);
grid on;
legend(handle_plot_Marker,text_legend,0);``````

## 平滑一个数据量很少的曲线

``````x0 = x(index);
y10 = y1(index);
y20 = y2(index);
y30 = y3(index);
text_legend = {};
text_legend{1,1} = 'y10';
text_legend{2,1} = 'y20';
text_legend{3,1} = 'y30';
figure
set(gcf,'color','w');
hold on;
handle_plot = [];
handle_plot(1) = plot(x0,y10,'-','color',[rand rand rand],'LineWidth',2);
handle_plot(2) = plot(x0,y20,'-','color',[rand rand rand],'LineWidth',2);
handle_plot(3) = plot(x0,y30,'-','color',[rand rand rand],'LineWidth',2);
grid on;
legend(handle_plot,text_legend,0)``````

matlab中插值函数为interp1，样式为：yi=interp1(x,y,xi,'spline')，x,y为原来的值，xi为需要插值的x值，yi为插值后的结果

``````y1i=interp1(x0,y10,x,'spline');
y2i=interp1(x0,y20,x,'spline');
y3i=interp1(x0,y30,x,'spline');

text_legend = {};
text_legend{1,1} = 'y1i';
text_legend{2,1} = 'y2i';
text_legend{3,1} = 'y3i';
figure
set(gcf,'color','w');
hold on;
handle_plot = [];
handle_plot(1) = plot(x,y1i,'-','color',[rand rand rand],'LineWidth',2);
handle_plot(2) = plot(x,y2i,'-','color',[rand rand rand],'LineWidth',2);
handle_plot(3) = plot(x,y3i,'-','color',[rand rand rand],'LineWidth',2);
grid on;
legend(handle_plot,text_legend,0);``````

## 绘制面积图

matlab里绘制面积图使用fill函数，fill(x,y,color)函数前两个参数一一对应组成一个点序列,如: x=[x1,x2,x3……xn],y=[y1,y2,y3……yn],fill函数将会从(x1,y1)点开始(x2,y2),(x3,y3)……绘制一个区域， 到(xn,yn)然后再连接（x1,y1），在这个封闭区域里填充颜色

``````text_legend = {};
text_legend{1,1} = 'y1 = 2*sin(x)+2.1';
text_legend{2,1} = 'y2 = sin(x).*cos(x)+2.2';
text_legend{3,1} = 'y3 = sin(x)./(x+0.1)+2';
figure
set(gcf,'color','w');
hold on;
handle_plot = [];
handle_plot(1) = plot(x,y1,'-','color',[rand rand rand],'LineWidth',2);
fill([x(1) x x(end)],[0 y1 0],[0.77,0.90,0.94]);
handle_plot(2) = plot(x,y2,'-','color',[rand rand rand],'LineWidth',2);
handle_plot(3) = plot(x,y3,'-','color',[rand rand rand],'LineWidth',2);
grid on;
legend(handle_plot,text_legend,0);``````

``````text_legend = {};
text_legend{1,1} = 'y1 = 2*sin(x)+0.1';
text_legend{2,1} = 'y2 = sin(x).*cos(x)+0.2';
text_legend{3,1} = 'y3 = sin(x)./(x+0.1)';
figure
set(gcf,'color','w');
hold on;
handle_plot = [];
line_color = [rand rand rand];
handle_plot(1) = plot(x,y1,'-','color',line_color);
fill([x(1) x x(end)],[0 y1 0],line_color,'edgealpha',0.4,'FaceAlpha',0.4);

line_color = [rand rand rand];
handle_plot(2) = plot(x,y2,'-','color',line_color);
fill([x(1) x x(end)],[0 y2 0],line_color,'edgealpha',0.4,'FaceAlpha',0.4);

line_color = [rand rand rand];
handle_plot(3) = plot(x,y3,'-','color',line_color);
fill([x(1) x x(end)],[0 y3 0],line_color,'edgealpha',0.4,'FaceAlpha',0.4);
grid on;
legend(handle_plot,text_legend,0);``````

matlab还是能画出比较漂亮的图的…

### 尘中远

【图像处理知识复习】01画灰度直方图matlab, C++ 实现

jizhidexiaoming
05/07
0
0
iPhone图形开发绘图小结

iPhone图形开发绘图教程是本文要介绍的内容，介绍了很多关于绘图类的使用，先来看详细内容讲解。 1、绘图总结: 绘图前设置: 绘图后设置: 注: 画完图后,必须 先用CGContextStrokePath来描线,...

junwong
2012/03/01
1K
0
Android View 绘图流程

View 绘图流程 API 和 Displayer View -> Draw -> Canvas -> C API -> OpCode Byte -> IO -> GPU CARD -> Electronic signal -> Displayer Android提供了一套View机制，封装好了需要控件，只......

2016/04/20
33
0

HuangRui1991
2017/05/17
1
0

2013/03/09
341
0

whoru
10分钟前
0
0
TiDB EcoSystem Tools 原理解读系列（二）TiDB-Lightning Toolset 介绍

TiDB
12分钟前
0
0

14分钟前
0
0
Maven环境隔离

Maven环境隔离 1. 什么是Maven环境隔离 顾名思义，Maven环境隔离就是将开发中的环境与beat环境、生产环境分隔开，方便进行开发和维护。这个在实际项目中用的还是很多的，如果你的项目用的Mav...

14分钟前
1
0
day182-2018-12-19-英语流利阅读-待学习

“性感”时代已去，维密将如何转身？ Daniel 2018-12-19 1.今日导读 维多利亚的秘密（Victoria's Secret）这个内衣品牌，最近似乎步入了“中年危机”——曾经打遍天下的“性感”内衣，在主打...

14分钟前
2
0