How to plot single row values of 2 .mat files with linear regression line through it

1 visualización (últimos 30 días)
I have a 2 datasets of .mat files which contain 1*418 matrix in both the .mat files how to plot the regression line for that. I have plottedd the scatter plot for it after that i couldnot able to proceed.
can any one help me.
Thank you.

Respuesta aceptada

Reshma Nerella
Reshma Nerella el 3 de Mzo. de 2020
To add the regression line, you can use polyfit and polyval functions.
load SI_Aorta
load SI_Femoral
% Plot regression line
poly = polyfit(x,y,n) % n is the order of polynomial
y_val = polyval(poly,x) % find estimated values of y
hold on % to add plot to existing scatter plot
plot(x,y_val);
hold off
  1 comentario
Rik
Rik el 3 de Mzo. de 2020
It is better practice to load the variables to a struct. Then it is clear where all the data is coming from.
S=load('SI_Aorta.mat');x=S.x;
S=load('SI_Femoral.mat');y=S.y;
poly = polyfit(x,y,n);% n is the order of polynomial
y_val = polyval(poly,x);% find estimated values of y using the polynomial(poly)
figure(1),clf(1)
plot(x,y,'.');
hold on
plot(x,y_val);
hold off

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Polynomials 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!

Translated by