create a loop/ switch elements

3 次查看(过去 30 天)
Marco Carapellese
编辑: KSSV 2022-3-4
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 个评论
Benjamin Thompson
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 2022-3-3
The code cannot run due to missing closing parentheses:
if i==t(v)+(greentime(1,v)
% ^ ^ ???

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by