ฉันกำลังพยายามเพิ่มเส้นแนวโน้มให้กับพล็อต semilogx
แต่ไม่สำเร็จ ฉันต้องการเส้นแนวโน้มระหว่าง y(17)
ถึง y(20)
แต่ไม่ได้ลงจุดเป็นเส้นตรง
นี่คือรหัสของฉัน:
%// Define equation.
x = [90868 68151 45434 34076 27261 13631 6816 3408 2273 1948 1705 1137 853 683 569 455 342 274 228 190];
y = [3680 3723 3800 3866 3920 4103 4250 4320 4340 4344 4350 4364 4373 4379 4384 4393 4398 4402 4405 4407];
%// Plot it
semilogx(x,y, 'bo-', 'LineWidth', 3);
grid on;
%// Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
%// Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
%// Fit the y data range with a line (limitedRange).
limitedRange = 17:20;
coeffs = polyfit(x(limitedRange), y(limitedRange), 1);
xFitting = linspace(200, 90000, 50);
yFitted = polyval(coeffs, xFitting);
%// Plot the fitted line over the specified range.
hold on;
plot(xFitting, yFitted, 'ro-', 'LineWidth', 2);
legend('Original Data', 'Line Fit');
ฉันจะทำให้เส้นแนวโน้มปรากฏเป็นเส้นได้อย่างไร?