Clear Filters
Clear Filters

How to change the y-axis values to start at 0 and not become negative?

28 views (last 30 days)
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

Accepted Answer

Jan
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
Muhammad Choudhury
Muhammad Choudhury on 29 Apr 2021
Edited: Muhammad Choudhury on 29 Apr 2021
Apologies the constants were not changed from a previous video i processed, essentially what I wanted to do was begin at at 1.7 on my y-axis and begin end at 1 on my x-axis but couldn't get it to work. This is what I tried using next:
scatter(1-posVec(:,1),1.7-posVec(:,2));
For the last code you provided I am getting an error saying:
"Index in position 2 exceeds array bounds (must not exceed 1).
Error in Tennis (line 50)
scatter(1-posVec(:,1),1.7-posVec(:,2));"
I'm not quite sure what to do here.

Sign in to comment.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!