How to perform a loop in which values from first leg are taken into second leg?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a code which looks like this
%leg 1
a = 0
b = 0
c = 4500
t = 90./60
cend = 4400
%leg 2
a = 6
b = 55
c = cend
t = 30./60
%leg 3
a = 7.5
b = 80
c = cend
t = 50./60
%calculation
(large calculation which includes variables a, b, c & t)
I want to take the precalculated variables from '%leg 1', and plug them into the '%calculation' part of the code. This then returns a value for 'cend', which i then want to take into leg 2, before recalulating the %calculation part of the code with the new values listed in %leg 2. Then i want to repeat this step for %leg 3; altogether I have 9 legs and so I'm rather confused due to the scale of the problem. Is there a way I can create this loop? Thank you!
3 comentarios
David Fletcher
el 12 de Abr. de 2021
I'm not saying you don't need a loop (I have no real idea of what you are doing, so I can't really comment, but maybe you want a loop around the 'legs' if the a,b,c,and t parameters are easily calculable from cend). However, the 'calculation' seems to be a common element, takes the same input and returns the same output, so it would make sense to turn it into a function. Maybe (and like I say I have no real idea of what you are doing, so it's only speculaltion on my part), you want something like:
Initialize cend with first value
loop over however many legs you've got
calculate a,b,c & t from cend value ('legs')
call calculation function and get new value for cend
end loop with final cend value
Respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!