for loop/indexing assistance for simple plot script

1 次查看(过去 30 天)
hey everyone,
I'm working on a hmwk assignment where I have to use function handles to create points for a plot. I'm allowed 1 for loop to run through an array A for different angles, which I then calculate and plot trajectories for. here is my code, currently I get a plot of one trajectory, and it doesn't seem to run through all the values of A, only the first. any help would be appreciated.
clc clear
%constants
g= 1.62;%m/s v= 10; %m/s A= [15 30 45 60 75]'; %degrees
%functions with handles tof,h,x tof=@(A)(2*v/g)*sind(A); %time of flight h=@(t,A)v.*t*sind(A)-.5*g*(t.^2); %height of ball x=@(t,A)v.*t*cosd(A); %horizontal distance
hold all for i=1:length(A) ts=tof(A(i)); t=linspace(0,ts,30); H=h(t(:),A(i)); X=x(t(:),A(i));
end plot(X,H)

采纳的回答

bym
bym 2012-7-9
Move your plot command to inside the loop, as in:
clc; clear
%constants
g= 1.62;%m/s
v= 10; %m/s
A= [15 30 45 60 75]'; %degrees
%functions with handles tof,h,x
tof=@(A)(2*v/g)*sind(A); %time of flight
h=@(t,A)v.*t*sind(A)-.5*g*(t.^2); %height of ball
x=@(t,A)v.*t*cosd(A); %horizontal distance
hold all
for i=1:length(A)
ts=tof(A(i));
t=linspace(0,ts,30);
H=h(t(:),A(i));
X=x(t(:),A(i));
plot(X,H)
end

更多回答(1 个)

Joe
Joe 2012-7-9
thanks!!!!

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by