2016-11-05 72 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