Adding average line to scatter plot

25 ビュー (過去 30 日間)
Yasmine
Yasmine 2013 年 1 月 27 日
編集済み: Image Analyst 2023 年 7 月 7 日
Hi there, I have 2 columns matrix(x, y) I found their linear regression line and plotted it on scatter plot, the problem is I still need to plot the line of Y averages values on same scatter plot, how do I calculate this averages of y ..can any one help?
  1 件のコメント
Image Analyst
Image Analyst 2013 年 1 月 27 日
OK you plotted the regression line on the scatter plot so you have both of those, but what is "Y averages values"? Is that just yaveragesValues = mean(Y(:))? So it's just the average of all y values or fitted y values or something different?

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2013 年 1 月 27 日
編集済み: Image Analyst 2023 年 7 月 7 日
See this demo:
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
format compact;
x = 1:100;
noiseSignal = 10*rand(1, length(x))
y = x + noiseSignal
plot(x, y, 'bo');
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 a line through the data
coefficients = polyfit(x, y, 1);
% Get the fitted values
fitted_y = polyval(coefficients, x);
% Plot the fitted values
hold on;
plot(x, fitted_y, 'r', 'LineWidth', 3);

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by