Plotting help. No line or points appearing on plot

So, im trying to write a script to plot x=x1 + tV1cos(theta). The figure will generate but no points. What can I do to fix this? Any help would be extremely appreciated. Thank you in advance
%% Get user input
launch_angle= input('Enter launch angle in degrees : ');
xo = input('Enter initial x position in meters: ');
xt = input('Enter target x position in meters: ');
yt = input('Enter target y position in meters: ');
tt = input('Enter target hitting time in seconds: ');
te = input('Enter end time in seconds: ');
g=9.8;
% Calculate Vo
vo = (xt-xo)/(tt*(cos(launch_angle * (pi/180))))
%% Display the result
disp(['Initial Velocity in metres per second is: ', num2str(vo)]);
%% Calculate yo
yo = yt - (tt*vo*(sin(launch_angle * (pi/180))))+(0.5*g*tt^2)
%% Display the result
disp(['Initial y positon in metres is: ', num2str(yo)]);
%% Equations to plot End pt
xe = xo + (te*vo*cos(launch_angle * (pi/180)))
ye = yo + (te*vo*(sin(launch_angle * (pi/180))))-(0.5*g*te^2)
%% Plot end point
figure
plot(xe',ye','-r');

댓글 수: 1

Hi
I suspect you wanted to plot the full trajectory, but you're simply plotting one (the end) point
If you don't see it maybe it's because you have not choosen the right options : try : plot(xe',ye','*r');
nvertheless, you have to write the equation of the trajectory first before you can plot it

댓글을 달려면 로그인하십시오.

 채택된 답변

VBBV
VBBV 2020년 10월 23일
편집: VBBV 2020년 10월 23일
You need to make time as vector. Then you can plot the trajectory, if i understand it right.
See the code below, it plots xe vs ye according to your prog
launch_angle= input('Enter launch angle in degrees : ');
xo = input('Enter initial x position in meters: ');
xt = input('Enter target x position in meters: ');
yt = input('Enter target y position in meters: ');
tt = input('Enter target hitting time in seconds: '); % total time to hit target in s
te = input('Enter end time in seconds: '); % end time at which target is destroyed
g=9.8;
te = tt:-0.1:te; % calculate the time vector
% Calculate Vo
vo = (xt-xo)/(tt*(cos(launch_angle * (pi/180))))
%% Display the result
disp(['Initial Velocity in metres per second is: ', num2str(vo)]);
%% Calculate yo
yo = yt - (tt*vo*(sin(launch_angle * (pi/180))))+(0.5*g*tt^2)
%% Display the result
disp(['Initial y positon in metres is: ', num2str(yo)]);
%% Equations to plot End pt
xe = xo + (te*vo*cos(launch_angle * (pi/180)))
ye = yo + (te*vo*(sin(launch_angle * (pi/180))))-(0.5*g*te.^2)
%% Plot end point
figure
plot(xe',ye','-r');

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Waveform-Level Simulations에 대해 자세히 알아보기

질문:

2020년 10월 22일

편집:

2020년 10월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by