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(1 次) トレンドラインを描きたいと思います。どうすればいいのかわかりません。

私は本当にあなたの助けに感謝します

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 に答える