漂亮,美观的图表之Matlab强势回归~~~~走你1

1.首先使用Matlab画一个简单的图

如下:

 

针对这幅图;

对于x,y坐标系的标签,title.我们很容易写出,

%% Label
xlabel(['Independent Variable: ' headerLabels{1}]);
ylabel(['Dependent Variable: ' headerLabels{2}]);

Title

title({'The linear least squares fit',...
    'overlaid on scatter plot view of sorted data'});


其中headerLabels是cell数组,用于存放x,y坐标系的标签,

红色线条和蓝色点是拟合线和数据点,可以通过

plotfit,polyval函数获得,最后通过plot画出。

左上角的小方框是用legend画出来的, 很简单。

numericData是50*2的数组,headerLabels是1*2 cell

代码如下:

%% Read data in from an excel spreadsheet
[numericData headerLabels]=xlsread('TemperatureXL.xls');
%% Sort data to aid in its visualization (on the independent variable)
[sortedResults I] = sort(numericData(:,1));
%% Plot data
plot(numericData(I,1), numericData(I,2),'.');  
set(gcf,'Paperpositionmode','auto','Color',[1 1 1]);
%% Label
xlabel(['Independent Variable: ' headerLabels{1}]);
ylabel(['Dependent Variable: ' headerLabels{2}]);
title('Scatter plot view of sorted data');

%% Hold axes to overlay more data
hold on; 
%% Obtain a linear fit for this data using polyfit (polynomial of degree 1)
p = polyfit(numericData(I,1),numericData(I,2),1);
y = polyval(p,numericData(I,1));
%% Plot the linear fit in red
plot(numericData(I,1),y,'r--');
%% Title, legend and print
legend({'Data','Fit'},'Location','NorthWest');
title({'The linear least squares fit',...
    'overlaid on scatter plot view of sorted data'});


 

第一篇写的匆匆忙忙,下面的系列希望逻辑写的可以完整点。

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值