Finding the endpoint (tip) in a figure

8 views (last 30 days)
Hello Matlab Community,
As shown, this is a figure i generated using matlab. I want to obtain only the endpoints(in red dot) of the figure. Then use the obtain points to plot dotted points.
I tried using the findpeak function but i realized certain endpoints of the values are missing and i couldnot find the points either.
Thanking you in advance

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 27 Jan 2022
Edited: Fangjun Jiang on 27 Jan 2022
It looks like the figure is created by using stem(). If you created the figure, won't you have the data for the "red dot" already?
x=0:0.1:2*pi;
y=sin(x);
stem(x,y,'MarkerFaceColor','red')
  5 Comments
Fangjun Jiang
Fangjun Jiang on 31 Jan 2022
findpeaks() is the right function to use. You may need to play with the arguments.
Evans Gyan
Evans Gyan on 2 Feb 2022
Thank you Fangjun for your response. I finally managed to get it working. This is how i code it
x=0:0.1:2*pi;
y = diric(2*pi*x,5);
n = 6; % define the no of interval for division
nopts= fix(size(x,2)/n); % neccessary no of apex (tip) points
l = 1;
for jj = 1:n:size(x,2)-n
[h(l) inx] = max(y(1,jj:n+jj));
c = jj:n+jj;
c1(l) = c(inx)
l = l+1;
end
x1 = x(c1);
figure;stem(x,y,'MarkerFaceColor','red')
figure;stem(x1,h,'MarkerFaceColor','red')

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!