How can plot the residuals as vertical distances from the data point to the fitted curve
6 次查看(过去 30 天)
显示 更早的评论
采纳的回答
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 个评论
dpb
2014-5-2
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 ???
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
