Plot sigma value to linear curve

1 Ansicht (letzte 30 Tage)
Joakim Karlsson
Joakim Karlsson am 23 Feb. 2018
Beantwortet: SRT HellKitty am 23 Feb. 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

Antworten (1)

SRT HellKitty
SRT HellKitty am 23 Feb. 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

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by