How can plot the residuals as vertical distances from the data point to the fitted curve

 채택된 답변

dpb
dpb 2014년 5월 2일
편집: dpb 2014년 5월 2일
If your data are x,y and yh the predicted values, then
scatter(x,y) % the data circles
hold on
plot(x,yh,':') % the regression line
arrayfun(@(x,y,yh) line([x x],[y yh],'linestyle','-'),x,y,yh) % the stem lines
NB: the x,y,yh in the @(x,y,yh) portion of the anonymous function are dummy arguments substituted into the function definition by reference; the actual data are the three arrays as given as the arguments to arrayfun.
doc arrayfun % for more details and anonymous functions.
Takes same number of plotting commands as S-Strider's solution but dispenses with the duplicated data for the lines data array at the expense of a little complexity in arrayfun

댓글 수: 1

Seems like a good request for enhancement to stem, though...I couldn't figure out any way to fool it and its source code is quite complex enough didn't care to try to mung on it for just this ???

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jack
Jack 2014년 5월 3일
Thank your all guys, either way is to construct those lines and plot them separately, I thought there are build-in function.

댓글 수: 1

For many things there are but not this particular one. stem only works from the baseline; won't take an arbitrary reference. Which is why I suggested file an enhancement request.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

태그

질문:

2014년 5월 2일

댓글:

dpb
2014년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by