Find specific points on a graph.

조회 수: 10 (최근 30일)
Kwesi Moore
Kwesi Moore 2017년 8월 26일
댓글: Kwesi Moore 2017년 8월 28일
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
Jonas
Jonas 2017년 8월 26일
Why don't you use the cursor to get the index of the points?
Kwesi Moore
Kwesi Moore 2017년 8월 28일
@Image Analyst; you realise that this is the turning point. The point where the descent begins uniformly.
@Jonas, yes, I already used the cursor to find these points but this is not helpful if I have thousands of such data (204-by-2) and need to find point D for all the data.

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
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')
  댓글 수: 1
Kwesi Moore
Kwesi Moore 2017년 8월 28일
This is almost the same as my code written in an elegant way. However, the position D for which i posted my code has not been addressed. Any tips will be helpful.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Direct Search에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by