How to change the y-axis values to start at 0 and not become negative?
    27 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Muhammad Choudhury
 am 29 Apr. 2021
  
    
    
    
    
    Bearbeitet: Muhammad Choudhury
 am 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

0 Kommentare
Akzeptierte Antwort
  Jan
      
      
 am 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 Kommentar
  Muhammad Choudhury
 am 29 Apr. 2021
				
      Bearbeitet: Muhammad Choudhury
 am 29 Apr. 2021
  
			
		Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Image Preview and Device Configuration finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


