I've been trying for a while to find the following edges on a graph as shown in the picture below
The following code is for the path and plot
path_test=[ 106 20;
107 19;
108 18;
109 17;
110 16;
111 15;
112 14;
113 13;
114 12;
114 11;
114 10;
115 9;
116 9;
117 9;
118 9;
119 9;
120 9;
121 9;
122 9;
123 9;
124 9;
125 9;
126 9;
127 9;
128 10;
129 10;
130 10];
plot(path_test(:,2),path_test(:,1),'b');
I've tried to use islocalmin and ischange as shown bellow
index1=islocalmin(path_test,'FlatSelection','first');
index2=islocalmin(path_test,'FlatSelection','last');
index3=ischange(path_test);
index = [index1 index2 index3];
path_index=[];
for i=1:length(index)
if (any(index(i,:))==1 && all(index(i,:))==0)
path_index = [path_index i];
end
end
figure(11)
plot(path_test(:,2),path_test(:,1),'b');
hold on
plot(path_test(path_index,2),path_test(path_index,1),'rX')
And to use all of these commands alone, but i only get the following points shown in the plot below
With only findlocalmin i get the following
I was woundering if anyone know about a way to find the points of interest?

 채택된 답변

darova
darova 2020년 2월 12일

3 개 추천

Better solution
x = path_test(:,2);
y = path_test(:,1);
dangle = diff( diff(y)./diff(x) );
ind = find(abs(dangle) > 0.1)+1;
hold on
plot(x(ind),y(ind),'or')
hold off

댓글 수: 2

Per Gunnar Torvund
Per Gunnar Torvund 2020년 2월 12일
Thanks alot, this worked like a charm!
Frank Pernett
Frank Pernett 2020년 9월 9일
Thank you!. This worked even better than finding peaks!

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

추가 답변 (1개)

KSSV
KSSV 2020년 2월 12일

1 개 추천

A very quck implementation.....canbe further refined and more elegant solution possible.
p =[ 106 20;
107 19;
108 18;
109 17;
110 16;
111 15;
112 14;
113 13;
114 12;
114 11;
114 10;
115 9;
116 9;
117 9;
118 9;
119 9;
120 9;
121 9;
122 9;
123 9;
124 9;
125 9;
126 9;
127 9;
128 10;
129 10;
130 10];
x = p(:,2) ;
y = p(:,1) ;
m = gradient(y)./gradient(x) ;
[c,ia,ib] = unique(m) ;
iwant = cell(length(c),1) ;
for i = 1:length(c)
iwant{i} = [x(ib==i) y(ib==i)] ;
end
figure
hold on
plot(x,y,'r')
for i = 1:length(c)
tx = iwant{i}(:,1) ; ty = iwant{i}(:,2) ;
plot([tx(1) tx(end)],[ty(1),ty(end)],'*k')
end

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2020년 2월 12일

댓글:

2020년 9월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by