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

조회 수: 40 (최근 30일)
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

채택된 답변

Jan
Jan 2021년 4월 29일
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
Muhammad Choudhury
Muhammad Choudhury 2021년 4월 29일
편집: Muhammad Choudhury 2021년 4월 29일
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.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by