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 Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by