search string in array that contain other arrays
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi everyone. Given the vector that I am attaching, which is a set of other vectors, I would like to search among the 'Phases' and do some operations if any of these 'phases' contain the string 'G'. However I cannot implement it. An follow the code I am trying. Thanks in advance
I know that the commands "in" are not read for this reason I was looking for your help. I need the for loop and the if
Thank you
for phase in logic_list{1, 1}.phases
if 'G' in phase.state
phase.duration = 10;
traci.trafficlights.setCompleteRedYellowGreenDefinition('B1',logic_list);
logic_list = traci.trafficlights.getCompleteRedYellowGreenDefinition('B1');
print(logic_list);
end
end
댓글 수: 3
Jan
2022년 2월 16일
It looks like the elements of the cell array phases are objects of the class Phase. I do not know this class.
채택된 답변
Voss
2022년 2월 17일
Maybe this:
for ii = 1:numel(logic_list{1}.phases)
if contains(logic_list{1}.phases{ii}.state,'G')
% do stuff
end
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!