フィルターのクリア

for loop/indexing assistance for simple plot script

1 回表示 (過去 30 日間)
Joe
Joe 2012 年 7 月 9 日
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 Center および File Exchange2-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