Effacer les filtres
Effacer les filtres

search string in array that contain other arrays

2 vues (au cours des 30 derniers jours)
Marco Carapellese
Marco Carapellese le 16 Fév 2022
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 commentaires
Marco Carapellese
Marco Carapellese le 16 Fév 2022
are you sure? because I just double checked, you have to open the cell, to be able to access the other nested cells. I report an example in the screens that I am attaching
Jan
Jan le 16 Fév 2022
It looks like the elements of the cell array phases are objects of the class Phase. I do not know this class.

Connectez-vous pour commenter.

Réponse acceptée

Voss
Voss le 17 Fév 2022
Maybe this:
for ii = 1:numel(logic_list{1}.phases)
if contains(logic_list{1}.phases{ii}.state,'G')
% do stuff
end
end

Plus de réponses (0)

Catégories

En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by