strcmp not working correctly

12 vues (au cours des 30 derniers jours)
Haziq Razali
Haziq Razali le 11 Juil 2019
Modifié(e) : madhan ravi le 11 Juil 2019
I have 2 datas. behaviours_currframe.ID and label.
behaviours_currframe.ID =
3×1 cell array
{'pedestrian4'}
{'ped2' }
{'ped3' }
label =
'pedestrian4'
I am trying to do strcmp
mask = strcmp({behaviours_currframe.ID}, label);
mask
But why is the output
mask =
logical
0
Why is it 0 ? There is one item in behaviours_currframe.ID that is similar to label.

Réponses (2)

Aiswarya Subramanian
Aiswarya Subramanian le 11 Juil 2019
Modifié(e) : madhan ravi le 11 Juil 2019
Hello,
You can use the following syntax instead:
behaviours_currframe.ID = {'pedestrian4' ,'ped2' ,'ped3'};
label = 'pedestrian4';
mask = strcmp(label, behaviours_currframe.ID);
disp(mask);
Hope this helps!!

Alex Mcaulley
Alex Mcaulley le 11 Juil 2019
Modifié(e) : Alex Mcaulley le 11 Juil 2019
The problem is in your call to strcmp:
behaviours_currframe.ID = {'pedestrian4','ped2', 'ped3'};
label = 'pedestrian4';
mask = strcmp(behaviours_currframe.ID, label)
mask =
1×3 logical array
1 0 0

Catégories

En savoir plus sur Labels and Annotations dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by