How to get the regression from 2 vectors
조회 수: 11 (최근 30일)
이전 댓글 표시
Hi, I have 2 vectors and I would like to know the R^2 ie the regression of the line. I would like a line of best fit to show on the plot and the two vectors one on y and one on x axis thanks
댓글 수: 1
Image Analyst
2013년 11월 23일
편집: Image Analyst
2013년 11월 23일
Here is what Shani asked, so that it will still be here when she deletes this question:
subject line: How to get the regression from 2 vectors
Hi, I have 2 vectors and I would like to know the R^2 ie the regression of the line. I would like a line of best fit to show on the plot and the two vectors one on y and one on x axis thanks
답변 (1개)
Image Analyst
2013년 11월 22일
Try this demo:
% Create sample data and plot it.
x = 1:10;
y = 3*x - 20 + 4*rand(1, length(x)); % Some equation
plot(x, y, 'r*', 'MarkerSize', 15);
grid on;
% Get the fit
coeffs = polyfit(x, y, 1);
% Get the x values for the fit at higher resolution.
xFit = linspace(x(1), x(end), 300);
% Get the estimated y values
yFit = polyval(coeffs, xFit);
% Plot them as a line.
hold on;
plot(xFit, yFit, 'b-', 'LineWidth', 3);
댓글 수: 1
Image Analyst
2013년 11월 22일
편집: Image Analyst
2013년 11월 22일
My x and y are vectors. What do you have? Give code to generate the kind of data you have.
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!