Plot sigma value to linear curve

조회 수: 5 (최근 30일)
Joakim Karlsson
Joakim Karlsson 2018년 2월 23일
답변: SRT HellKitty 2018년 2월 23일
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

답변 (1개)

SRT HellKitty
SRT HellKitty 2018년 2월 23일
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

카테고리

Help CenterFile Exchange에서 Fit Postprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by