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')

剧情结果图片

这是对数比例。在这个图上,我想绘制 y=ax+b(1st order) 趋势线。我不知道该怎么做。

我将非常感谢您的帮助

4

1 回答 1

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');

这是您的对数比例趋势: 在此处输入图像描述

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

在此处输入图像描述

于 2016-11-06T21:40:13.503 回答