How to perform a loop in which values from first leg are taken into second leg?

7 vues (au cours des 30 derniers jours)
Bob Wake
Bob Wake le 11 Avr 2021
Commenté : David Fletcher le 12 Avr 2021
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 commentaires
Bob Wake
Bob Wake le 12 Avr 2021
I'm not sure how I'd go about this? I was convinced I'd need some sort of loop to looked like this;
%leg 1
%calculation (returns value for cend)
%leg 2 (cend from %leg 1 placed here)
%calculation (returns value for cend)
%leg 3 (cend from leg2 placed here)
David Fletcher
David Fletcher le 12 Avr 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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by