How to add trendline to scatterplot?

1,151 次查看(过去 30 天)
hi, I have 2 variables with data, like
x=2 1 4 68 4 5
y=5 4 2 23 21 50
I want to add trendline to the scatter plot. how can I do that?

采纳的回答

Ameer Hamza
Ameer Hamza 2020-12-27
Something like this
x = [2 1 4 68 4 5]
y = [5 4 2 23 21 50]
p = polyfit(x, y, 1);
px = [min(x) max(x)];
py = polyval(p, px);
scatter(x, y, 'filled')
hold on
plot(px, py, 'LineWidth', 2);

更多回答(1 个)

Dima
Dima 2024-3-17,8:48
编辑:Dima 2024-3-17,8:50
x = [2 1 4 8 4 5]
y = [5 4 2 53 21 50]
p = polyfit(x, y, 1);
px = [min(x) max(x)];
py = polyval(p, px);
scatter(x, y, 'filled')
lsline
lsline command.

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by