I have 2 vectors and i want to obtain a correlation between them like y=ax+b by using regression, but i don't know how to use this code. would anyone help me with this?

 Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Mzo. de 2017

0 votos

coeffs = polyfit(FirstVector, SecondVector, 1);
Then coeffs(1) will be your a, and coeffs(2) will be your b.

4 comentarios

Ghazal Hnr
Ghazal Hnr el 12 de Mzo. de 2017
Isn't any way to write with regression code?
Walter Roberson
Walter Roberson el 12 de Mzo. de 2017
That is regression code.
A different way of writing the same thing:
A = [FirstVector(:), ones(numel(FirstVector),1)];
b = SecondVector(:);
coeffs = A\b;
Ghazal Hnr
Ghazal Hnr el 12 de Mzo. de 2017
thank you very much
Walter Roberson
Walter Roberson el 12 de Mzo. de 2017
Note that when I say "a different way of writing the same thing", I mean that polyfit() really does construct those matrices and use the \ operator.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 12 de Mzo. de 2017

Comentada:

el 12 de Mzo. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by