Find edges in a plot
11 views (last 30 days)
Show older comments
Per Gunnar Torvund
on 12 Feb 2020
Commented: Frank Pernett
on 9 Sep 2020
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?
0 Comments
Accepted Answer
darova
on 12 Feb 2020
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 Comments
More Answers (1)
KSSV
on 12 Feb 2020
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
0 Comments
See Also
Categories
Find more on Multirate Signal Processing 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!