Find specific points on a graph.
Ältere Kommentare anzeigen
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 Kommentare
Image Analyst
am 26 Aug. 2017
Since point D does not protrude outward like the other points, please tell us how it is like the other points.
Jonas
am 26 Aug. 2017
Why don't you use the cursor to get the index of the points?
Kwesi Moore
am 28 Aug. 2017
Antworten (1)
KSSV
am 28 Aug. 2017
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')
1 Kommentar
Kwesi Moore
am 28 Aug. 2017
Kategorien
Mehr zu Direct Search finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!