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