필터 지우기
필터 지우기

create a loop/ switch elements

조회 수: 2 (최근 30일)
Marco Carapellese
Marco Carapellese 2022년 3월 3일
편집: 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
Benjamin Thompson 2022년 3월 3일
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에서 Programming에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by