How to change the y-axis values to start at 0 and not become negative?
15 views (last 30 days)
Show older comments
Muhammad Choudhury
on 29 Apr 2021
Edited: Muhammad Choudhury
on 29 Apr 2021
How can i make it so that my plot starts at 0 and doesn't go below 0 into the negative numbers, also I'd like to use a range from 0 to 1.7 on my y-axis but am unable to. Thank you!
clc;
close all;
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(65-posVec(:,1),365-posVec(:,2));
pbaspect([1000 1000 1000])
hold on;
title('Bouncing Ball Trajectory')
xlabel('Horizontal Displacement')
ylabel('Vertical Displacement')
This is what I am getting so far
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/600480/image.png)
0 Comments
Accepted Answer
Jan
on 29 Apr 2021
It is not clear, what you are asking for.
You can limit the Y axis by:
ylim([0, 1.7])
This would crop almost all points from the diagram.
Maybe you want to scale the data instead. Where do the constants in this expression come from:
scatter(65-posVec(:,1),365-posVec(:,2));
% ^^ ^^^ ?
What about:
posVec = -posVec;
posVec = posVec - min(posVec); % Starting at 0
posVec = 1.7 * posVec / max(posVec); % maximum value scaled to 1.7
1 Comment
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!