how to plot the lower or upper boundary lines for scatter data?

15 views (last 30 days)
Hi
I have a scatter plot. I'd like to plot the lines connecting the points either the upper or lower bound.
How to do it?
Could you please help? Thank you so much.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Jan 2018
You could use boundary() to help figure out which points are on the perimeter. Figuring out which of those points are on the upper or lower branch might take some thinking for irregular point distributions.
  1 Comment
roudan
roudan on 30 Jan 2018
Thanks Walter. It indeed takes some time to figure out how to find the lower bounds points.
Here are my codes and it works for my case
% if trendline is for boundary line
if ~isempty(strfind(trendlinecoverage,'bound')) % find the lowerbound string
k=boundary(xdata_crossplot',ydata_crossplot'); % have to be column vector
boundarypoint=[];
startx=k(1);
maxindex=length(k);
boundarypoint=[boundarypoint startx];
for i=2:maxindex
currentpointindex=k(i);
previouspointindex=k(i-1);
if xdata_crossplot(currentpointindex)>xdata_crossplot(previouspointindex) % we are moving in x+ direction to find the lower boundary point
boundarypoint=[boundarypoint k(i)];
end
end
hold(hrightsubplot,'on');
legendlabel_boundary='lower boundary line'
hp=plot(hrightsubplot,xdata_crossplot(boundarypoint),ydata_crossplot(boundarypoint),'-b','linewidth',2,'DisplayName',legendlabel_boundary);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!