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

2 visualizaciones (últimos 30 días)
Muhammad Choudhury
Muhammad Choudhury el 29 de Abr. de 2021
Comentada: Muhammad Choudhury el 29 de Abr. de 2021
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')

Respuesta aceptada

DGM
DGM el 29 de Abr. de 2021
Editada: DGM el 29 de Abr. de 2021
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 comentarios
DGM
DGM el 29 de Abr. de 2021
Editada: DGM el 29 de Abr. de 2021
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 el 29 de Abr. de 2021
Perfect thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by