Plot sigma value to linear curve

5 vues (au cours des 30 derniers jours)
Joakim Karlsson
Joakim Karlsson le 23 Fév 2018
Hi all. I am trying to figure out how to plot the sigma value to the linear curve. I have my code down below and a figure of what I want to do.
%
td=[-1 0 1 2 3 4 6 7]';
yd=[-0.75 0.3 3 4 5.6 7 6.4 8.4]';
A=[ones(size(td)) td];
x=A\yd; a=x(1); b=x(2);
n=length(td);
e=norm(A*x-yd)/sqrt(n)
y=a+(b*td);
plot(td,y,); hold on
My code now plots the linear curve and calculates all values that I need, and the final thing I need is to plot the green lines that are sort of "errors". The image I got is a screenshot of what I want to achieve.
Thanks, Joakim

Réponses (1)

SRT HellKitty
SRT HellKitty le 23 Fév 2018
To get a vertical line you use the a simple 2 element vector where x does not change(to make a horizontal line simply make the y constant) such as;
plot([xConstant, xConstant], [yStart, yEnd])
So for that first green line in the image above that goes from (-1, -1) to (-1,0) it would look like this;
plot([-1, -1], [-1 0])
now to add this into a for loop you could do the following, which will create the lines you request;
for ii = 1:length(td)
plot([td(ii), td(ii)], [yd(ii), y(ii)])
end

Catégories

En savoir plus sur Fit Postprocessing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by