常用Matlab作图命令.doc
《常用Matlab作图命令.doc》由会员分享,可在线阅读,更多相关《常用Matlab作图命令.doc(27页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、常用Matlab作图命令1.概率统计作图1.1绘出正态分布的密度函数曲线x=-5:0.1:5; y=normpdf(x,0,1);z=normpdf(x,0,2);plot(x,y,x,z)gtext(N(0,1)gtext(N(0,2)title(正态分布密度曲线)1.2绘出t-分布的密度函数曲线,并与标准正态密度曲线比拟x=-5:0.1:5;y=tpdf(x,30);z=normpdf(x,0,1);plot(x,y,k:,x,z,k-)xlabel(itx);ylabel(概率密度itp)legend(t分布, 标准正态密度)difference=tpdf(x,30)-normpdf(x
2、,0,1) 绘制开方分布密度函数在n分别等于1、5、15的图x=0:1:30;y1=chi2pdf(x,1);plot(x,y1,:)hold ony2=chi2pdf(x,5);plot(x,y2,+)y3=chi2pdf(x,15);plot(x,y3,O)Axis(0,30,0,0.2) 计算自由度是50,10的F-分布的的分位数,并给出概率与分位数关系的图形t=0:0.1:4;y=fpdf(x,50,10);z=fpdf(t,50,10);plot(t,z,x,x,0,y)text(x,0,2.1171)gtext(p=0.9)title(概率与分位数的关系)1.5 经验累积分布函数图
3、形X=normrnd (0,1,50,1);h,stats=cdfplot(X)y = evrnd(0,3,100,1);cdfplot(y)hold onx = -20:0.1:10;f = evcdf(x,0,3);plot(x,f,m)legend(Empirical,Theoretical,Location,NW)1.6 绘制正态分布概率图形X=normrnd(0,1,50,1);normplot(X)1.7 绘制威布尔(Weibull)概率图形%绘制威布尔(Weibull)概率图形的目的是用图解法估计来自威布尔分布的数据X,如果X是威布%尔分布数据,其图形是直线的,否那么图形中可能产
4、生弯曲。r = weibrnd(1.2,1.5,50,1);weibplot(r)1.8 样本数据的盒图%boxplot(X) %产生矩阵X的每一列的盒图和“须图,“须是从盒的尾部延伸出来,并表示盒外数据长度的线,如果“须的外面没有数据,那么在“须的底部有一个点。x1 = normrnd(5,1,100,1);x2 = normrnd(6,1,100,1);x = x1 x2;boxplot(x,1,g+,1,0)1.9 样本的概率图形 data=normrnd (0,1,30,2); p=capaplot(data,-2,2)p =1.10 附加有正态密度曲线的直方图r = normrnd
5、(10,1,100,1);histfit(r)1.11 在指定的界线之间画正态密度曲线格式 p = normspec(specs,mu,sigma) %specs 指定界线,mu,sigma 为正态分布的参数p为样本落在上、下界之间的概率normspec(10 Inf,11.5,1.25) 二项分布的函数图p = 0.2; % Probability of success for each trialn = 10; % Number of trialsk = 0:n; % Outcomesm = binopdf(k,n,p); % Probability mass vectorbar(k,m)
6、 % Visualize the probability distributionset(get(gca,Children),FaceColor,.8 .8 1)grid on1.13 指数分布函数图lambda = 2; % Failure ratet = 0:0.01:3; % Outcomesf = exppdf(t,1/lambda); % Probability density vectorplot(t,f) % Visualize the probability distributiongrid on1.14 ksdensity概率密度估计函数cars = load(carsmal
7、l,MPG,Origin); MPG = cars.MPG;f,x,u = ksdensity(MPG);plot(x,f)title(Density estimate for MPG)hold onf,x = ksdensity(MPG,width,u/3);plot(x,f,r);f,x = ksdensity(MPG,width,u*3);plot(x,f,g);legend(default width,1/3 default,3*default)hold offhname = normal epanechnikov box triangle;colors = r b g m;for j
8、=1:4 f,x = ksdensity(MPG,kernel,hnamej); plot(x,f,colorsj); hold on;endlegend(hname:);hold off2.常用作图函数普通双函数图t = 0:pi/20:2*pi;y = exp(sin(t);plotyy(t,y,t,y,plot,stem)xlabel(X Axis)ylabel(Plot Y Axis)title(Two Y Axes)多数据集在同一图中x = 0:pi/100:2*pi;y = sin(x);y2 = sin(x-.25);y3 = sin(x-.5);plot(x,y,x,y2,x,
9、y3)legend(sin(x),sin(x-.25),sin(x-.5)在原图上继续作图hold onx,y,z = peaks;pcolor(x,y,z)shading interphold oncontour(x,y,z,20,k)hold off同一图中作多个图clearx= 0.1:0.1:4*pi; % 生成向量x。y1=sin(x); % 生成y 1值y2=sin(x) ./x; % 生成y 2值。figure; % 创立一个新窗口。subplot(1, 2, 1); % 定义第一个子图区域。plot(x, y1); % 用实线画曲线。subplot(1, 2, 2); % 定义
10、第二个子图区域。plot(x,y2,*); % 用*号画曲线clear;x = 1 3 7;y = 6 9 2;s1 = subplot(2,2,1);plot(x,y);grid;title(Default);s2 = subplot(2,2,2);plot(x,y);set(s2,XTick,x); 改变X轴标记set(s2,XGrid,on); 画X轴的格栅线title(X scale manipulated);s3 = subplot(2,2,3);plot(x,y);set(s3,YTick,2,6,9); 改变y轴标记set(s3,YGrid,on); 画y轴的格栅线set(s3,
11、GridLineStyle,-.); 使用虚线格栅title(Y scale manipulated);s4 = subplot(2,2,4);plot(x,y);set(s4,XTick,x); 改变xy轴标记set(s4,YTick,2 6 9);grid; 画xy轴的格栅线title(Both scales manipulated);clf reset %Clearing the Figure for a New Plott = 0:pi/10:2*pi;X,Y,Z = cylinder(4*cos(t);subplot(2,2,1); mesh(X)subplot(2,2,2); me
12、sh(Y)subplot(2,2,3); mesh(Z)subplot(2,2,4); mesh(X,Y,Z)标签的显示(字符参照Latex标准)t = -pi:pi/100:pi;y = sin(t);plot(t,y)axis(-pi pi -1 1)xlabel(-pi leq itt leq pi)ylabel(sin(t)title(Graph of the sine function)text(1,-1/3,itNote the odd symmetry.)2.6 多元变量作图X,Y = meshgrid(-8:.5:8);R = sqrt(X.2 + Y.2) + eps;Z =
13、 sin(R)./R;mesh(X,Y,Z,EdgeColor,black) %使用mesh(X,Y,Z)采用默认颜色;定义函数作图function myfunc(x)% x = -10:.005:40; Heres a value you can use for xy = 1.5*cos(x) + 6*exp(-.1*x) + exp(.07*x).*sin(3*x);ym = mean(y);hfig = figure(Name,Function and Mean,.Pointer,fullcrosshair);hax = axes(Parent,hfig);plot(hax,x,y)ho
14、ld onplot(hax,min(x) max(x),ym ym,Color,red)hold offylab = get(hax,YTick);set(hax,YTick,sort(ylab ym)title (y = 1.5cos(x) + 6e-0.1x + e0.07xsin(3x)xlabel(X Axis); ylabel(Y Axis)使用fplot作图函数subplot(2,2,1);fplot(humps,0 1)subplot(2,2,2);fplot(abs(exp(-j*x*(0:9)*ones(10,1),0 2*pi)subplot(2,1,2);fplot(ta
15、n(x),sin(x),cos(x),2*pi*-1 1 -1 1) %后面参数表示x,y上下界;2.9 给当前图形加一条参考线y = 3.2 2.6 3.1 3.4 2.4 2.9 3.0 3.3 3.2 2.1 2.6;plot(y,+)refline(0,3)2.10 在当前图形中参加一条多项式曲线格式 h = refcurve(p) %在图中参加一条多项式曲线,h 为曲线的环柄,p 为多项式系数向量,p=p1,p2, p3,pn,其中p1 为最高幂项系数h = 85 162 230 289 339 381 413 437 452 458 456 440 400 356;plot(h,+
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 常用 Matlab 作图 命令
限制150内