1、第一,下图Excel是Damon,Stefan,Elena,Catherines四人January-December的工资报表(Excel的名字为salary.xlsx)。
2、第二,打开MATLAB,新建脚本(Ctrl+N),输入下面代码,读取Excel工资表,并绘制四人一月到十二月的工资线图。close all; 艘早祓胂clear all; clcdata=xlsread('salary.xlsx',1);Months=1:1:12;Damon=data(1,:);Stefan=data(2,:);Elena=data(3,:);Catherines=data(4,:);plot(Months,Damon,'-r','linewidth',3);hold on;plot(Months,Stefan,'-y','linewidth',3);plot(Months,Elena,'-g','linewidth',3);plot(Months,Catherines,'-b','linewidth',3);hold off;set(gca,'fontname','Time New Romans','fontsize',15,...'xtick',[1:1:12],'ytick',[600:100:1200]);axis([0,13,500,1200])其中xlsread('salary.xlsx',1)为读取Excel表格(salary.xlsx)数据,plot( )是绘制线图,set(gca,...)是设置图形坐标字体和标注,axis([ ])是设置坐标轴范围。
3、第三,保存和运行上述脚本,得到下图:Damon,Stefan,Elena,Catherines四人一月到十二月的工资线图。
4、第四,在工作区(Work Place)能看到从Excel读取到的数据。
5、第五,给第三步中的图形添加图例,输入下面代码:legend('Damon'巳呀屋饔,'Stefan','Elena','Catherines','location','northwest')
6、第六,保存和运行上述脚本,得到最终的图形,图形左上角为添加的图例。