matlab画柱状图matlab画柱状图和折线图放在一起的




matlab画柱状图matlab画柱状图和折线图放在一起的

2022-07-21 2:24:10 网络知识 官方管理员



今天小编为大家带来matlab三维绘图

01

本期主题介绍

Thetopicofthisissue

如果您了解过Matlab,

您肯定知道Matlab不只是计算!

Matlab还有一个强大的绘图功能!

本期话题将对matlab的三维图进行介绍。

请感兴趣的朋友和小编开启

学习Matlab的三维绘图之旅吧!

IfyouknowMatlab,

YoumustknowthatMatlabismorethanjustcomputing!

Matlabalsohasapowerfuldrawingfunction!

Thetopicofthisissuewillintroducethethree-dimensionaldrawingofmatlab.

Pleaseopenitwithinterestedfriendsandeditors

Learnthejourneyoftwo-dimensionaldrawinginMatlab

02

Matlab三维绘图

Matlab3Ddrawing

1.用plot绘制三维图形

Useplottodrawthree-dimensionalgraphics

x=1:5;

y=6:10;

z=x+y;

z2=exp(x+y);

[x3,y3]=meshgrid(x,y);

z3=x3+y3;

plot3(x,y,z);

plot3(x,y,z2);

plot3(x3,y3,z3);

%mesh可以绘制一段区间的曲面,调用格式mesg(x,y,z)

%注意:在使用函数前,先对xy平面建立网格坐标:[x,y]=meshgrid(x,y)

%其中meshgrid为二维三维网格

meshcandrawasectionofcurvedsurface,calltheformatmesg(x,y,z)

Note:Beforeusingthefunction,creategridcoordinatesonthexyplane:[x,y]=meshgrid(x,y)

Wheremeshgridisatwo-dimension althree-dimensionalgrid

matlab画柱状图()(1)

2.绘制螺旋图

Drawaspiralgraph

t=0:pi/60:10*pi;

x=sin(t);

y=cos(t);

plot3(x,y,t,'*-b');

matlab画柱状图()(2)

3.三维网格图

Three-dimensionalgridmap

mesh函数用于绘制三维网格图,其调用语法如下。
(1)mesh(x,y,z):绘制三维网格图,x、y、z分别表示三维网格图形在x轴、y轴和z轴的坐标,图形的颜色由矩阵z决定。mesh(Z):绘制三维网格图,分别以矩阵Z的列下标、行下标作为三维网格图的x轴、y轴的坐标。

注意事项:在使用函数前,需要先在xy平面建立网格坐标:[x,y]=meshgrid(x,y),然后再利用新的x,y计算网格上对应z的点,从而得到构建曲面所需的点,最后再使用mesh绘制整个图。

Themeshfunctionisusedtodrawathree-dimensionalgridgraph,anditscallingsyntaxisasfollows.

(1)mesh(x,y,z):drawathree-dimensionalgridgraph,x,y,zrepresentthecoordinatesofthethree-dimensionalgridgraphonthex-axis,y-axisandz-axis,respectively.Thecolorofthegraphisdeterminedbythematrixz.mesh(Z):Drawathree-dimensionalgridgraph,andusethecolumnsubscriptsandrowsubscriptsofmatrixZasthecoordinatesofthex-axisandy-axisofthethree-dimensionalgridgraph.

Note:Beforeusingthefunction,youneedtoestablishthegridcoordinatesinthexyplane:[x,y]=meshgrid(x,y),andthenusethenewx,ytocalculatethepointcorrespondingtozonthegridtogetConstructthepointsneededforthesurface,andfinallyusethemeshtodrawtheentiregraph.

x=-8:8;

y=-8:8;

[X,Y]=meshgrid(x,y);

Z=(X.^2/4^2-Y.^2/5^2);

meshz(X,Y,Z)

matlab画柱状图()(3)

4.绘制柱状图

Drawahistogram

bar3(x,y,z);

bar3(z3);

bar3(z3,'grouped')

bar3(z3,'stacked')

bar3(z3,0.3)

matlab画柱状图()(4)

5.绘制直方图

Drawahistogram

%X=randn返回一个从标准正态分布中得到的随机标量。

%X=randn(n)返回由正态分布的随机数组成的n×n矩阵。

%X=randn(sz1,...,szN)返回由随机数组成的sz1×...×szN数组,其中sz1,...,szN指示每个维度的大小。例如:randn(3,4)返回一个3×4的矩阵。

%histogram为绘制直方图

%X=randnreturnsarandomscalarobtainedfromthestandardnormaldistribution.

%X=randn(n)returnsann×nmatrixcomposedofnormallydistributedrandomnumbers.

%X=randn(sz1,...,szN)returnsansz1×...×szNarraycomposedofrandomnumbers,wheresz1,...,szNindicatethesizeofeachdimension.Forexample:randn(3,4)returnsa3×4matrix.

%histogramistodrawahistogram

x4=randn(100,1);

y4=randn(100,1);

histogram2(x4,y4);

matlab画柱状图()(5)

6.绘制饼图

Drawapiechart

pie3(z3)

matlab画柱状图()(6)

7.绘制“火柴杆图”

Drawa"matchstickmap"

%火柴杆数

%Matchsticks

stem3(x3,y3,z3)

t=-10:0.1:10;

xt=t;

yt=sin(t);

zt=exp(t);

stem3(xt,yt,zt,'filled');

matlab画柱状图()(7)

matlab画柱状图()(8)

8.空间曲面绘图

Spacesurfacedrawing

%suf空间曲面绘图

%surf(x,y,z)画出数据点x,y,z表示的曲面

%画出z=(x+y)^2

%sufspacesurfacedrawing

%surf(x,y,z)drawsthesurfacerepresentedbydatapointsx,y,z

%Drawoutz=(x+y)^2

x=-2:0.1:4;

y=1:0.2:8;

[x,y]=meshgrid(x,y);

z=(x+y).^3;

surf(x,y,z)

shaingflat

matlab画柱状图()(9)

9.subplot的使用,以及shading自由设置图形表面的颜色

Theuseofsubplotandshadingfreelysetthecolorofthegraphicsurface

%shaingflat使用同一种颜色配色

%shadinginterp插值处理方式配色

%shaingflatusesthesamecolor

%shadinginterpcolormatching

figure

subplot(1,3,1)

sphere(16)

axisequal

title('FacetedShading(Default)')

subplot(1,3,2)

sphere(16)

shadingflat

axisequal

title('FlatShading')

subplot(1,3,3)

sphere(16)

shadinginterp

axisequal

title('iInterpolatedShading')

matlab画柱状图()(10)

10.绘制极坐标图

Drawpolarcoordinates

a=10

k=2

theta=0:pi/50:2*pi;

r=a*sin(k*theta);

h=polar(theta,r)

set(h,'color',[1,0,0],'LineWidth',2)

matlab画柱状图()(11)

今天的分享就到这里了。


发表评论:

最近发表
网站分类
标签列表