首页 > 编程知识 正文

怎么把excel导入matlab,matlab导入两组数据并绘图

时间:2023-05-05 09:55:10 阅读:18142 作者:3040

目录

1 .在表格中准备需要画画的数据

2. matlab加载excel数据

基于data画画

3.1直线图

3.2条形图

4 .设置要绘制的图形的x坐标下标

5 .更改下标的显示方向:倾斜效果(如果x轴的下标重叠,则为下图) ) ) ) ) ) ) ) ) ) ) )

6 .添加图例

7 .设置条形图中不同圆柱形的颜色

读取excel中不同shell的数据

9 .在不同的线条上添加图标标记,设定x坐标范围和间隔

10 .从0开始改变x坐标轴,或者改变x坐标轴的显示参数

1. excel里准备好需要绘画的数据2. matlab加载excel中的数据data=xls read (' th BPM-results.xlsx ',1 ); 读取excel数据的data图3.1直线图data=xls read (' th BPM-results.xlsx ',1 ); plot(data ) 1:e、1:e

nd),'DisplayName','data(1:end,1:end)'); %绘制折线图

3.2 柱形图 >> data = xlsread('thBPM-Results.xlsx');>> bar(data(1:end,1:end),'DisplayName','data(1:end,1:end)'); %绘制柱形图

4. 设置绘制图形的X坐标下标 >> data = xlsread('thBPM-Results.xlsx');>> plot(data(1:end,1:end),'DisplayName','data(1:end,1:end)'); %绘制折线图>> set(gca,'Xticklabel',{'x_a','x_b ','x_c','x_d','x_e','x_f','x_g','x_h'});

5. 改变下标显示方向:倾斜效果(当x轴下标出现重合之时,如下图)

此时设置方法为:

>> data = xlsread('thBPM-Results.xlsx');>> plot(data(1:end,1:end),'DisplayName','data(1:end,1:end)'); %绘制折线图>> set(gca,'Xticklabel',{'uci_labour','uci_weekends ','102_labour','102_weekends','104_labour','104_weekends','110_labour','110_weekends'});>> set(gca,'XTickLabelRotation',45); %设置x坐标下标倾斜45度

显示效果为:

6. 添加图例 >> data = xlsread('thBPM-Results.xlsx');>> plot(data(1:end,1:end),'DisplayName','data(1:end,1:end)'); %绘制折线图>> set(gca,'Xticklabel',{'uci_labour','uci_weekends ','102_labour','102_weekends','104_labour','104_weekends','110_labour','110_weekends'});>> set(gca,'XTickLabelRotation',45); %设置x坐标下标倾斜45度>> legend('a','b','c','d'); %添加图例

7. 设置柱形图不同柱形的颜色

关于颜色参照:https://www.jianshu.com/p/46af0b95ead7

>> data = xlsread('thBPM-Results.xlsx');>> bar1 = bar(data(1:end,1:end),'DisplayName','data(1:end,1:end)'); %绘制柱形图>> set(gca,'Xticklabel',{'uci_labour','uci_weekends ','102_labour','102_weekends','104_labour','104_weekends','110_labour','110_weekends'}); %设置横坐标>> set(gca,'XTickLabelRotation',45); %设置x坐标下标倾斜45度>> legend('Accuracy(Outlier)','Recall(Outlier)','Accuracy(Interestingness)','Recall(Interestingness)'); %添加图例>> set(bar1(1),'facecolor',[0 0.447 0.741]) %设置不同圆柱体颜色>> set(bar1(2),'facecolor',[0.85 0.325 0.098])>> set(bar1(3),'facecolor',[0.929 0.694 0.125])>> set(bar1(4),'facecolor',[0.4667 0.6745 0.1882])

8. 读取excel中不同sheet的数据 >> data = xlsread('thBPM-Results.xlsx', 2); %默认获取第一个sheet>> bar1 = bar(data(1:end,1:end),'DisplayName','data(1:end,1:end)'); %绘制柱形图>> set(gca,'Xticklabel',{'uci_labour','uci_weekends ','102_labour','102_weekends','104_labour','104_weekends','110_labour','110_weekends'}); %设置横坐标>> set(gca,'XTickLabelRotation',45); %设置x坐标下标倾斜45度>> legend('Accuracy(Outlier)','Recall(Outlier)','Accuracy(Interestingness)','Recall(Interestingness)'); %添加图例>> set(bar1(1),'facecolor',[0 0.447 0.741]) %设置不同圆柱体颜色>> set(bar1(2),'facecolor',[0.85 0.325 0.098])>> set(bar1(3),'facecolor',[0.929 0.694 0.125])>> set(bar1(4),'facecolor',[0.4667 0.6745 0.1882])

9. 给不同线条添加图标marker,及设置X坐标范围及间隔 >> data = xlsread('thBPM-Results.xlsx', 5); %默认获取第一个sheet>> plot1 = plot(data(1:end,1:end),'DisplayName','data(1:end,1:end)'); >> set(gca,'XTick',[0:1:4]) %改变x轴坐标间隔显示 这里间隔为1>> legend('uci_labour','uci_weekends ','102_labour','102_weekends','104_labour','104_weekends','110_labour','110_weekends'); %添加图例>> set(plot1(1),'marker','+') %设置不同线条线型>> set(plot1(2),'marker','*') %设置不同线条线型>> set(plot1(3),'marker','.') %设置不同线条线型>> set(plot1(4),'marker','x') %设置不同线条线型>> set(plot1(5),'marker','s') %设置不同线条线型>> set(plot1(6),'marker','d') %设置不同线条线型>> set(plot1(7),'marker','^') %设置不同线条线型>> set(plot1(8),'marker','p') %设置不同线条线型

10. 改变x坐标轴从0开始,或改变x坐标轴显示参数 >> data = xlsread('thBPM-Results.xlsx', 5); %默认获取第一个sheet>> plot1 = plot(data(1:end,1:end),'DisplayName','data(1:end,1:end)'); >> legend('uci_labour','uci_weekends ','102_labour','102_weekends','104_labour','104_weekends','110_labour','110_weekends'); %添加图例>> set(plot1(1),'marker','+') %设置不同线条线型>> set(plot1(2),'marker','*') %设置不同线条线型>> set(plot1(3),'marker','.') %设置不同线条线型>> set(plot1(4),'marker','x') %设置不同线条线型>> set(plot1(5),'marker','s') %设置不同线条线型>> set(plot1(6),'marker','d') %设置不同线条线型>> set(plot1(7),'marker','^') %设置不同线条线型>> set(plot1(8),'marker','p') %设置不同线条线型>> set(gca,'XTick',1:1:4) %改变x轴坐标间隔显示 这里间隔为1>> set(gca,'Xticklabel',{'0','1','2','3'}); %设置横坐标

转载于https://blog.csdn.net/u010637291/article/details/88913981

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。