How to make axis continuous based on input
3 次查看(过去 30 天)
显示 更早的评论
Hi, ive written a code based on projectile motion, and created a GUI with the intent to create an app as a project for university. The issue I run into is my x axis is pre-defined, I was wondering is there a way to change it to where it constantly increased until the line reaches zero in the y-direction, e.g. (6,0) or (58.53,0). In the code below the main block will be in the button callback section. The code below is just the script I use to test, as the forum did not let me post the GUI but its the same without the restrictions.
Thanks in advance!
%======================================================================%
%Arrow is fired from a cliff plot its projectile motion 10m above ground at
%20 m/s
%======================================================================%
clear all %clears workspace
%angle = 0.4; %Size of angle it is fired at in radians from cliff
V0 = 20; %inital velocity = 20 m/s
g = -9.81; %Gravity force taking up as +ive
t = 0:0.1:4; %time
%t = zeros(30);
%h = 10; %height
%Ax = 0; %Vertical Acceleration
Ay = g; %Horizontal Acceleration
%======================================================================%
%xVelocity = V0 * cos(angle);
yVelocity = V0 * sin(angle); %Vertical Velocity
x = t; %x axis = time
y = h + (yVelocity * t + (1/2) * Ay * t.^2); %s = ut + (0.5)at^2
y = max(0,y);
%======================================================================%
plot(x, y);%+10 BECAUSE 10M ABOVE GROUND
%%%%ADD IN LOOP TO STOP WHEN Y AXIS GOES BELOW ZERO THEN INCREASE
%%%%INCREMENTS
%======================================================================%
caption = sprintf('Angle = %.2f radians', angle); %Title of graph defined
title(caption, 'FontSize', 15); %Title of graph inserted
grid on; %Grid on graph
%======================================================================%
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
%======================================================================%
0 个评论
采纳的回答
Sebastian Castro
2017-4-11
编辑:Sebastian Castro
2017-4-11
For example, to do limits from 0 to 58 you would type
xlim([0 58])
To do axis limits as soon as a ground collision is detected, you could do something like:
% Find all the indices of y that are less than zero
zeroIdx = find(y < 0);
% If there are indices with altitude less than zero, find the first one and set the X axis limits
if ~isempty(zeroIdx)
finalPosition = y(zeroIdx(1));
xlim([0 finalPosition])
end
% Set all altitudes less than zero to zero (can't penetrate the ground!)
y(zeroIdx) = 0;
- Sebastian
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Title 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!