How to make axis continuous based on input
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mitul Dattani
el 11 de Abr. de 2017
Editada: Sebastian Castro
el 11 de Abr. de 2017
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 comentarios
Respuesta aceptada
Sebastian Castro
el 11 de Abr. de 2017
Editada: Sebastian Castro
el 11 de Abr. de 2017
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Title en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!