How can I display the y-axis at each maximum point

조회 수: 2 (최근 30일)
Muhammad Choudhury
Muhammad Choudhury 2021년 4월 29일
댓글: Muhammad Choudhury 2021년 4월 29일
Is there a way in determining the y-axis values at each maximum point of this graph.
clear all;
% Importing video from files
vid = VideoReader('portfolio3/Tennis1.mp4');
% Converting the video into frames
frames = read(vid);
% Finding the size and length of the video
si = size(frames)
% % Creating a vector to store positions of the vector
posVec = [];
%% Cropping and greying the video for facile processing
% for all frames
for i = 1 : si(4)
% Cropping frame by frame
CroppedFrame = imcrop(frames(:,:,:,i),[120 90 450 1000]);
% Coverting to grey
CroppedFrame = rgb2gray(CroppedFrame);
% Binarising
CroppedFrame = im2bw(CroppedFrame,0.7);
% Removing flexes
CroppedFrame = imopen(CroppedFrame,strel('disk',3));
imshow(CroppedFrame);
% Tracking the ball in the video
[pos,rad] = imfindcircles(CroppedFrame,[13 100]);
viscircles(pos,rad);
drawnow
% Adding the current position to the position vector
posVec = [posVec; pos];
end
scatter(0-posVec(:,1),500-posVec(:,2));
pbaspect([1000 1000 1000])
hold on;
title('Bouncing Ball Trajectory')
xlabel('Horizontal Displacement')
ylabel('Vertical Displacement')

채택된 답변

DGM
DGM 2021년 4월 29일
편집: DGM 2021년 4월 29일
You can find the y-val and location of local maxima using findpeaks()
[peaks,loc,w] = findpeaks(mydata);
Just doing
findpeaks(mydata);
plots the series and places markers on the peaks that it found.
For example:
t = linspace(0,8.5*pi,100);
f = -t.^2.*sin(t) + t.^2;
[pk,loc]=findpeaks(f)
findpeaks(f)
gives
pk =
0.1809 51.69 249.62 604.93 1118.3
loc =
4 21 43 66 89
  댓글 수: 3
DGM
DGM 2021년 4월 29일
편집: DGM 2021년 4월 29일
You should just be running it on the y-data. Normally, you could run it on both x and y vectors, but your x-data isn't strictly increasing. Passing the y-data alone should be sufficient.
Consider this example using scattered data with non-monotonic x-data:
% plot points in a circle
r = 1;
th = linspace(0,2*pi,30);
x = r*cos(th);
y = r*sin(th);
scatter(x,y); axis equal
[pk,loc] = findpeaks(y)
findpeaks(y)
pk =
0.99853
loc =
8
Muhammad Choudhury
Muhammad Choudhury 2021년 4월 29일
Perfect thank you!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by