Upper bound curve that passes through the extreme (highest) points
조회 수: 5(최근 30일)
표시 이전 댓글
I have a matrix of 100x2 data. When I used scatter plot, it looks like below.
Now, I want to plot a curve touching the extreme (highest) points looks like below:
I tried convex hull and got something like that which is not what I wanted. I also tried envelope but not worked as well.
Any suggestions please. Thank you.
Matt J 2023년 1월 29일
final_mat = ;
for i = 1:length(surhe_height_1m)
if surhe_height_1m(i) > 0.02
final_mat = [final_mat;D_by_t_u(i),surhe_height_1m(i)];
final_mat = [final_mat];
y = final_mat(:,2);
k = unique(convhull(final_mat));
댓글 수: 3
Image Analyst 2023년 1월 29일
I don't understand why the convex hull is not what you want. That's what I was going to suggest. Otherwise maybe you can try movmax
댓글 수: 1
John D'Errico 2023년 1월 29일
I would argue a convex hull is probably at least close to what is wanted. That it works here because the envelope is roughly a convex curve. The problem is most likely a misunderstanding of what a convex hull does or how to use it. But since we do not have the actual data, or even see how @Md Mia tried to use a convex hull, we are at a loss to offer better help.
In that light, I'll need to make up some data, that can show how a convex hull MIGHT have been used.
x = rand(200,1);
y = 1 - exp(-4*x) + randn(size(x))/20;
The goal in this exercise is to find a curve that represents the upper envelope of the data.
T = convhull(x,y)
The elements of T represent a list of references into the original data set, as the edges of the convex hull. I'll turn it into a polyshape to make things easy to plot.
PS = polyshape(x(T),y(T));
As you can see, the convex hull has edges both along the lower part of the curve, as well as the upper part.
What we want to retain however, are the edges that face upwards. We can extract them simply enough by discarding all edges that face downwards.
Choose a point that is well below the data.
[xc,yc] = centroid(PS);
% get the normal vector for each edge.
nt = numel(T);
e = 1:nt-1;
normalvecs = [x(T(e)) - x(T(e+1)),y(T(e)) - y(T(e+1))]*[0 -1;1 0];
% find the dot product of the normal vector for each edge
% with the vector connecting the midpoint of the edge and the centroid.
% this way we can insure the normal vectors are pointing outwards.
V = [x(T(e)),y(T(e))] - [xc,yc];
S = (sum(normalvecs.*V,2) > 0)*2 - 1;
normalvecs = normalvecs.*S
% The normal vectors with a negative y component here are facing downwards.
e(normalvecs(:,2) <= 0) = 
% now replot the data, with the upward facing portion of the convex hull,
% so the upper envelope.
Again, if that upper envelope would not be considered to be a convex curve, then a convex hull would be inappropriate. But it is.
댓글 수: 1
Walter Roberson 2023년 1월 30일
Find more on Computational Geometry in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!