Plot not showing up

When I run this code, the plot doesn't show up on the figure. Any idea why? Thanks in advance!
function [x , y] = trajectory(t)
% Function for varying time
for t=(0:.5:7)
x = (35 * cosd(65) * t);
y = (35*sind(65)*(t))-(4.905*(t.^2));
end
%Plot the solution
figure
title('Trajectory vs. Time')
xlabel('t')
ylabel('Trajectory')
plot(x,y);
hold on
end

Answers (1)

Try this:
% Function for varying time
t=(0:.5:7);
for k = 1:numel(t)
x(k) = (35 * cosd(65) * t(k));
y(k) = (35*sind(65)*(t(k)))-(4.905*(t(k).^2));
end
%Plot the solution
figure
title('Trajectory vs. Time')
xlabel('t')
ylabel('Trajectory')
plot(x,y,'p');
hold on
It is necessary to store the results in appropriate vectors, then plot them at the end.
This just plots with a marker. To plot with a line:
plot(x,y,'-r');
or a line and a marker:
plot(x,y,'-pg');
.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Asked:

on 12 Sep 2020

Answered:

on 12 Sep 2020

Community Treasure Hunt

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

Start Hunting!