不能在matlab gui的图表中完全包含绘图,仅显示一半的绘图

时间:2017-12-16 05:39:42

标签: matlab plot

这是一个射弹运动图,我已经包含了完整的计算,直到绘制图形为止。我不明白如何在计算部分之后使用代码更改图表的设置。 this is what i've plotted using this code below

time = linspace(0, t, 1000);
legends = {}; % Instantiate an empty cell for the angle legend.
counter = 1;
for A = 10: 10 : 90
% Get the components of velocity in the x and y directions for this angle.
vx = v*cosd(A);
vy = v*sind(A);
% Compute the distance along the x direction.  x = x0 + x_velocity * time.
xfinal = vx * time;
% Compute the distance along the y direction.  y = y0 + y_velocity_initial * 
%time + (1/2)*g*time^2
yfinal = vy * time + (1/2) * 9.81 * time .^ 2;
% Clip y to zero because we assume the projectile stays on the ground when 
%it hits.  
% It does not penetrate and have a negative y.
yfinal(yfinal < 0) = 0;
indexHitGround = find(yfinal > 0, 1, 'last');
fontSize=10
plot(xfinal, yfinal, '-', 'LineWidth', 2);
hold on;
legends{end+1} = sprintf('Angle = %d', A);
% Calculate the range in the x direction.
xFinal(counter) = xfinal(indexHitGround);
counter = counter + 1;
end
grid on;
xlabel('X Coordinate', 'FontSize', fontSize);
ylabel('Y Coordinate', 'FontSize', fontSize);
title ('Projectile Trajectory', 'FontSize', fontSize)
legend(legends);
% Find the max xFinal and set the range of the graph to be that.
xlim([0, max(xFinal)]);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0.2, 0.3, 0.8, 0.7]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Projectile Trajectory Demo Part 2', 'NumberTitle', 'Off')

而我试图策划这样的事情 projectile trajectory

我是matlab的新手,所以如果您指出我的代码中的错误或给我一些建议,我将非常感激。谢谢!

1 个答案:

答案 0 :(得分:2)

The problem is not in the way you plot the data but in the equation used to compute the trajectory.

You have to change the sign of the acceleration component to minus.

Change

yfinal = vy * time + (1/2) * 9.81 * time .^ 2;

to

yfinal = vy * time - (1/2) * 9.81 * time .^ 2;

In your code, t and v are not defined, I've used some values to test the code.

Also with respect to the picture of the desired graph, the y0 is not defined (and not used in the equation), perhaps you might change the equation to

yfinal = y0+ vy * time - (1/2) * 9.81 * time .^ 2;

setting y0=10 the trajectories look like:

enter image description here