Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How can I plot my data from my for loop?

1 Ansicht (letzte 30 Tage)
Mohammed Ahmed
Mohammed Ahmed am 18 Okt. 2020
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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

Antworten (1)

Durganshu
Durganshu am 19 Okt. 2020
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