分享兴趣,传播快乐, 增长见闻,留下美好。 亲爱的您, 这里是LearingYard学苑! 今天小编为大家带来matlab二维绘图 欢迎您的用心访问! 本期推文阅读时长大约5分钟,请您耐心阅读。 Shareinterest,spreadhappiness,increaseknowledge,andleavebeautiful。 Dearyou, ThisistheLearingYardAcademy! Today,theeditorbringsyoumatlabtwodimensionaldrawing Welcomeyourvisit! Thistweetusuallytakesabout5minutestoread,pleasereaditpatiently。 01。本期主题介绍 Topicintroductionofthisissu 在我们研究问题的过程中,对于模型结果分析,很多时候都需要运用图表来帮助我们去观察数据与数据之间的联系。这时候我们就可以充分利用MATLAB强大的绘图功能,来帮助我们解决问题。 那么,今天就跟随小编一起学习如何使用MATLAB的二维绘图吧! Intheprocessofourresearch,fortheanalysisofmodelresults,weoftenneedtousechartstohelpusobservetherelationshipbetweendataanddata。Atthistime,wecanmakefulluseofthepowerfuldrawingfunctionofMATLABtohelpussolveproblems。 So,letslearnhowtousethetwodimensionaldrawingofMATLABwithXiaobiantoday! 02。创建二维单线图 Create2Dsinglelinediagram (1)plot(x,y)用于绘制二维图形。 首先我们定义x为〔0,10〕的向量,然后将y创建为x的一次线性函数值。 Plot(x,y)isusedtodrawtwodimensionalgraphics。 First,wedefinexasavectorof〔0,10〕,andthencreateyasthelinearfunctionvalueofX。 (2)stairs(x,y)阶梯线条形状二维图形。 依旧定义x为〔0,10〕的向量,然后将y创建为x的一次线性函数值。 Stairs(x,y)ladderlineshapeistwodimensional。 Stilldefinexasavectorof〔0,10〕,andthencreateyasthelinearfunctionvalueofX。 (3)指定二维图线条形状。 依据前面所创建的函数,只需要在plot函数中指定形状即可,如:plot(x,y,)。 Specifiesthe2Dlineshape。 Accordingtothepreviouslycreatedfunction,youonlyneedtospecifytheshapeintheplotfunction,suchasplot(x,y,)。 (4)改变二维图形线条颜色。 要更改线条颜色可在plot(x,y)对组中添加线条设定输入参数。例如,g将绘制绿色直线。 Changethelinecolorof2Dgraphics。 Tochangethelinecolor,addlinestothegroupinplot(x,y)andsetinputparameters。Forexample,gwilldrawagreenline。 我们也可以同时指定线条形状和颜色,如r:,将绘制星标号的绿色点线。 Wecanalsospecifythelineshapeandcoloratthesametime,suchasr:,whichwilldrawthegreendottedlinewithStarlabel。 03。绘制二维多线图 Draw2Dmultilinegraph 绘制多个线条的二维图形方法与单线条类似。下面依旧用举例的方式进行解释。 Themethodofdrawingtwodimensionalgraphicsofmultiplelinesissimilartothatofasingleline。Thefollowingisstillexplainedbywayofexample。 (1)绘制多线条二维图形。 首先我们定义x为〔0,10〕的向量,并将y1和y2定义为两条平行的直线。 Drawmultiline2Dgraphics。 First,wedefinexasavectorof〔0,10〕,anddefineY1andY2astwoparallellines。 x0:10 y134x y264x plot(x,y1,x,y2) (2)指定线型和颜色。 依旧定义x为〔0,10〕的向量,并将y1和y2定义为两条平行的直线。如r表示颜色为红色的线条形状,我们也可以只改变颜色或只改变形状,直接表示为r或者。 Specifylinearandcolor。 Stilldefinexasavectorof〔0,10〕,anddefineY1andY2astwoparallellines。Forexample,Rindicatesthelineshapewithredcolor。Wecanalsochangethecolororshapeonly,whichisdirectlyexpressedasRor。 x0:10 y134x y264x plot(x,y1,r,x,y2,b:) 04。坐标轴设计 Coordinateaxisdesign 知道怎样绘制二维图形之后,我们来学习如何对坐标轴进行设计。 Afterknowinghowtodrawtwodimensionalgraphics,letslearnhowtodesignthecoordinateaxis。 (1)添加主题,坐标轴标签 使用title函数向图形添加标题,添加坐标轴标签;使用xlabel和ylabel函数向图形添加标题和坐标轴标签。 Addtheme,axislabels UUsethexlabelandylabelfunctionstoaddtitlesandaxislabelstothedrawing。 title(x与y一元线性图) xlabel(0x10)xaxislabel ylabel(y值)yaxislabel (2)添加图例。 使用legend函数向图形添加用于识别每个数据集的图例。按照绘制线条的顺序指定图例说明。 Addalegend。 Usethelegendfunctiontoaddalegendtothedrawingthatidentifieseachdataset。Specifiesthelegenddescriptionintheorderinwhichthelinesaredrawn。 legend(y134x,y264x) 05。总结 Summary 本文通过plot函数,学习了如何绘制单线条的二维图形,以及多线条的二维图形;在此基础之上,介绍了如何改变线条形状和颜色,以及怎样设置标题,坐标轴标签和图例。对于二维画图还有很多内容需要学习,今天的内容都是基础,我们要勤加练习,并不断学习这样才能更好的掌握MATLAB的使用。 Throughtheplotfunction,Onthisbasis,itintroduceshowtochangethelineshapeandcolor,andhowtosetthetitle,coordinateaxislabelandlegend。Thereisstillalottolearnabouttwodimensionaldrawing。Todayscontentisthefoundation。Weshouldpracticefrequentlyandkeeplearning,soastobettermastertheuseofMATLAB。 今天的分享就到这里了。 如果您对今天的文章有独特的想法, 欢迎给我们留言, 让我们相约明天, 祝您今天过得开心快乐! Thatsitfortodayssharing。 Ifyouhaveuniqueideasabouttoday’sarticle,pleaseleaveusamessage, Letusmeettomorrow, Iwishyouahappydaytoday! 参考资料:谷歌翻译、MATLAB软件 本文由LearningYard学苑原创,如有侵权请沟通。