How to plot a single column of values with a linear regression line through it
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
isamh
el 19 de Feb. de 2020
Comentada: darova
el 24 de Feb. de 2020
I have a column that I wann plot and have a regression line go through it, How would I do that?
my code so far is:
figure(1)
title('Phase1')
plot(FG)
5 comentarios
darova
el 24 de Feb. de 2020
- I added the: save('answers.mat', 'X', 'Y'); to both codes and still didnt the regression line.
Image Analyst can you cooperate?
Respuesta aceptada
darova
el 24 de Feb. de 2020
Here is a simple example (i made it special for you)
N = 20;
x = linspace(0,3,N);
y = 2*x + rand(1,N);
p = polyfit(x,y,1);
y1 = polyval(p,x);
plot(x,y,'.r')
hold on
plot(x,y1,'b')
hold off
- Forgot to mention that i have some NAN rows with both columns, would that effect the results?
Then you should do interpolation without NaN
ix = ~isnan(y); % choose indices that are not NaN
x1 = x(ix);
y1 = y(ix);
p = polyfit(x1,y1,1);
y2 = polyval(p,x1);
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!