Clear Filters
Clear Filters

create a loop/ switch elements

3 views (last 30 days)
Marco Carapellese
Marco Carapellese on 3 Mar 2022
Edited: KSSV on 4 Mar 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 Comments
Benjamin Thompson
Benjamin Thompson on 3 Mar 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 on 3 Mar 2022
The code cannot run due to missing closing parentheses:
if i==t(v)+(greentime(1,v)
% ^ ^ ???

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!