Plotting
6 ビュー (過去 30 日間)
古いコメントを表示
How to plot trajectory of an object when the angle of launch varies from 15-75 using 15 degree increments. I have the code to plot it. However, all the 4 plots are blue in color. How do I make it display different colored plots for different angles?
0 件のコメント
回答 (2 件)
Walter Roberson
2011 年 9 月 1 日
plot(t,h15,'r');
hold on
plot(t,h30,'g');
plot(t,h45,'b');
plot(t,h60,'c');
plot(t,h75,'m');
Or
plot(t,h15,'r',t,h30,'g',t,h45,'b',t,h60,'c',t,h75,'m')
Oleg Komarov
2011 年 9 月 1 日
Vectorized version, you can see here that the color is automatically selected for each column of y
y0 = 0;
v0 = 28;
g = 9.8;
x = 0:5:80;
th = 15:15:75;
y = bsxfun(@times,tand(th), x.') - bsxfun(@rdivide, g*x.',2*v0^2*cosd(th).^2) + y0;
plot (repmat(x.',1,5),y);
xlabel('distance 0-80');
ylabel('vertical displacement y');
axis square
Note that you legend accepts strings not doubles.
Otherwise use the syntax that Walter suggested:
y0 = 0; % m/s
v0 = 28; % m/s
g = 9.8; % acceleration due to gravity in m/s^2
x = 0:5:80; %distance from 0-100 in increments of 5
th = 15:15:75;
clr = {'r','g','b','c','m'}; % Colors
h = axes;
axis(h,'square');
hold on
for t = 1:numel(th)
y = tand(th(t))*x - g*x/(2*v0^2*cosd(th(t))^2) + y0;
plot(x,y,clr{t});
end
xlabel('distance 0-80');
ylabel('vertical displacement y');
Some suggestions, don't abuse the parenthesis and try to understand when you really need .* instead of *.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!