Filter löschen
Filter löschen

create a loop/ switch elements

2 Ansichten (letzte 30 Tage)
Marco Carapellese
Marco Carapellese am 3 Mär. 2022
Bearbeitet: KSSV am 4 Mär. 2022
hello everybody, I need to create a loop, for repeat the sum in the 'if'. And I need to reassign the same element at traci.trafficlights.setPhaseDuration like switch from the same element. Thanks
if i==t(v)+(greentime(1,v)
traci.trafficlights.setPhase('B1', 1)
traci.trafficlights.setPhaseDuration('B1', greentime(2,v))
end
end
if i==t(v)+(greentime(3,v)
traci.trafficlights.setPhase('B2', 1)
traci.trafficlights.setPhaseDuration('B2', greentime(4,v))
end
end
if i==t(v)+(greentime(1,v)+ (greentime(2,v)
traci.trafficlights.setPhase('B1', 0)
traci.trafficlights.setPhaseDuration('B1', greentime(1,v))
end
end
if i==t(v)+(greentime(3,v)+greentime(4,v)
traci.trafficlights.setPhase('B2', 0)
traci.trafficlights.setPhaseDuration('B2', greentime(3,v))
end
end
if i==t(v)+(greentime(1,v)+ (greentime(2,v)+(greentime(1,v)
traci.trafficlights.setPhase('B1', 1)
traci.trafficlights.setPhaseDuration('B1', greentime(2,v))
end
end
if i==t(v)+(greentime(3,v)+greentime(4,v)+(greentime(3,v)
traci.trafficlights.setPhase('B2', 1)
traci.trafficlights.setPhaseDuration('B2', greentime(4,v))
end
end
... and repeat this 'sum' until i reach a contition (for example T<90)
  2 Kommentare
Benjamin Thompson
Benjamin Thompson am 3 Mär. 2022
You can use the while keword to create loop that continues until T >= 90. To provide a better answer we need more information. I do not see any use of "sum" in your pseudocode. Can you try to code this up in MATLAB and then ask more specific questions and post your code?
Jan
Jan am 3 Mär. 2022
The code cannot run due to missing closing parentheses:
if i==t(v)+(greentime(1,v)
% ^ ^ ???

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by