How to make a for loop add results together consecutively?

1 Ansicht (letzte 30 Tage)
Hi, very new to Matlab and coding in general, I can't work out how to use a for loop to calculate individual results and add them together one by one as it progresses. I have a set of readings for acceleration at a fixed range of velocities, and my script can calculate the time taken to accelerate from each velocity reading to the next, but I cannot work out how to have my for loop add each time reading as it is calculated in order to plot time against velocity.
Airspeed.Thrust is a set of thrust readings from a separate table.
l = 2.4 %wingspan
m = 0.465+(l*0.1) %mass of aircraft
%calc
a = Airspeed.Thrust./m
%loop
t = 0
for v = 0:16
t = (1./a)
end
I tried to alter my loop to:
for v = 0:16
t = t+(1./a)
end
But for some reason this gives a completely different starting value, but produces an identically shaped graph.

Akzeptierte Antwort

David Hill
David Hill am 26 Jan. 2021
No loop is needed assuming your acceleration values are in an array.
v=0:16;
t=1./a;
plot(cumsum(t),v);

Weitere Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by