Info

此问题已关闭。 请重新打开它进行编辑或回答。

How can I plot my data from my for loop?

1 次查看(过去 30 天)
Mohammed Ahmed
Mohammed Ahmed 2020-10-18
关闭: MATLAB Answer Bot 2021-8-20
Please see my code below. I would like to plot v0 on the x-axis, and d on the y-axis.
I'm not really sure how I can save all of the data points from the for loop into plottable values.
clc
clear all
v0=50:1:100;
i=1
for i=1:length(v0);
syms t v0
eqn1 = (0 == v0-12.*(t-0.75)-v0+9.*t);
time=solve(eqn1,t)
syms d v0
eqn2 = (0 == ((v0.*0.75)+(v0.*time)-(v0.*0.75)+0.5.*(-12).*(time-0.75)^2-d-v0.*time+0.5.*(9).*time^2));
distance=solve(eqn2,d)
end

回答(1 个)

Durganshu
Durganshu 2020-10-19
I'm writing this answer on a mobile phone and thus, I havn't checked this code, but it should work:
clc
clear all
v0=50:1:100;
i=1
syms t v0
eqn1 = (0 == v0-12.*(t-0.75)-v0+9.*t);
time=solve(eqn1,t)
syms d v0
eqn2 = (0 == ((v0.*0.75)+(v0.*time)-(v0.*0.75)+0.5.*(-12).*(time-0.75)^2-d-v0.*time+0.5.*(9).*time^2));
distance=solve(eqn2,d)
plot(v0, distance);
hold on;
If it doesn't works, try putting the whole block inside for loop and iterate on individual values of v0. But, I think this method should also work.
You can also use fplot whose documentation can be found here: https://in.mathworks.com/help/matlab/ref/fplot.html
Hope that helps!

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by