2016-11-05 122 views
1

我正在编写一个在我的散点图上制作趋势线的代码。制作对数 - 对数比例散点图的趋势线

data=[]; 
for k=1:100 
    int=0; 
    for t=1:100 
     if k_star_90(k,t)~=0 
      int=int+k_star_90(k,t); 
     end 
     if k_star_90(k,t)==0 && int~=0 
      data=[data int]; 
      int=0; 
     end 
    end 
end 

intervals = linspace(0, 1, 100); 
h1 = histc(data, intervals); 
scatter(intervals, h1, 'r'); 
set(gca,'xscale','log') 
set(gca,'yscale','log') 

picture of plot result

这是对数刻度。在这个图上,我想绘制y = ax + b(一阶)趋势线。我不知道该怎么做。

我会很感激你的帮助

回答

0

我不知道我理解正确你的意图,但如果你需要一个趋势线可能会做这样的事

intervals = [0.01 0.02 0.2 0.1 0.3 0.5 0.03 0.4 0.15 0.2 0.2 0.25 1 0.9 0.8 0.8 0.7]; 
h1 =  [70 40 4 20 2 3 60 10 50 40 10 20 1 2 3 1 2] ; 

coeffs = polyfit(intervals, h1, 1); 
xFitting = 0:0.01:1; 
yFitted = polyval(coeffs, xFitting); 

scatter(intervals, h1, 'r'); 
set(gca,'xscale','log'); 
set(gca,'yscale','log'); 
grid on; 
hold on; 
plot(xFitting, yFitted, 'b', 'LineWidth', 2); 
hold off; 
ylim([1 80]); 

xlabel('intervals'); 
ylabel('h1'); 

这是您的趋势对数尺度: enter image description here

og当然它看起来不像一阶趋势。要将其描述为一条线,您需要返回到正常情节:

enter image description here