Find specific points on a graph.
显示 更早的评论
I have a data of 204-by-2 matrix that is shown in the image attached. I want to find the points A,B,C,D and E. I have attached my initial code to solve the problem but it didn't help with position D.
if true
% code
end
load pk_004.txt
x = pk_004(:,1); y = pk_004(:,2);k1 = convhull(x, y);
figure; plot(x,y,'r-',x,y,'b*')
figure; plot(x(k1),y(k1),'r-',x,y,'b*')
[v1, p1] = min(x); [v2, p2] = max(x);
[v1_, p3] = min(y); [v2_, p4] = max(y);
pos_A = pk_004(p1,:);
pos_C = pk_004(p2,:);
pos_B = pk_004(p4,:);
pos_E = pk_004(p3,:);
%compute area of True region A_1
A_1 = trapz(x,y);
% compute |BC|
dist_BC = pos_C(1) - pos_B(1);
% height of Parallelogram
H = abs(v2_ - v1_);
%Ideal region Parallelogram
% A_ideal = Base * Height = |BC| * H
A_id = dist_BC * H ;
% Compute ratio A_1/ A_id * 100
R_1 = A_1/A_id *100;
3 个评论
Image Analyst
2017-8-26
Since point D does not protrude outward like the other points, please tell us how it is like the other points.
Jonas
2017-8-26
Why don't you use the cursor to get the index of the points?
Kwesi Moore
2017-8-28
回答(1 个)
KSSV
2017-8-28
How about this approach? YOu may further fine tune it....
data = importdata('data.txt') ;
x = data(:,1) ;
y = data(:,2) ;
idx = convhull(x,y) ;
xi = x(idx) ; yi = y(idx) ;
m = gradient(yi)./gradient(xi) ;
plot(xi,yi,'r')
hold on
plot(x,y,'.b')
idx = find(diff(sign(m)))+1 ;
plot(xi(idx),yi(idx),'*r')
类别
在 帮助中心 和 File Exchange 中查找有关 Direct Search 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!