Expected Behavior for contains()?
Mostrar comentarios más antiguos
I am seeing odd behavior from the contains() function and I'm not sure if it's a bug or if it's working as expected.
I have two cell arrays of chars: rFootNames is 44x1 and eligNames is 33x1.
rFootNames={'RDP1';'RFCC';'RFM1';'RFM5';'RHeelCirc1';'RHeelCirc2';'RHeelCirc3';'RHeelCirc4';'RHeelCirc5';'RHeelCirc6';'RHeelCirc7';'RHeelCirc8';'RHeelCirc9';...
'RHeelCirc10';'RHeelCirc11';'RHeelCirc12';'RHeelCirc13';'RHeelCirc14';'RHeelCirc15';'RHeelCirc16';'RHeelCirc17';'RHeelCirc18';'RHeelCirc19';...
'RHeelCirc20';'RForeCirc1';'RForeCirc2';'RForeCirc3';'RForeCirc4';'RForeCirc5';'RForeCirc6';'RForeCirc7';'RForeCirc8';'RForeCirc9';'RForeCirc10';...
'RForeCirc11';'RForeCirc12';'RForeCirc13';'RForeCirc14';'RForeCirc15';'RForeCirc16';'RForeCirc17';'RForeCirc18';'RForeCirc19';'RForeCirc20'};
eligNames={'LFCC';'RDP1';'RFM1';'RFM5';'LHeelCirc8';'LHeelCirc9';'LHeelCirc10';'LHeelCirc11';'LHeelCirc12';'LHeelCirc13';'LHeelCirc14';'RHeelCirc1';...
'RHeelCirc2';'RHeelCirc3';'RHeelCirc4';'RHeelCirc5';'RHeelCirc6';'RHeelCirc19';'RHeelCirc20';'RForeCirc1';'RForeCirc2';'RForeCirc3';'RForeCirc4';'RForeCirc5';...
'RForeCirc12';'RForeCirc13';'RForeCirc14';'RForeCirc15';'RForeCirc16';'RForeCirc17';'RForeCirc18';'RForeCirc19';'RForeCirc20'};
When I run
rIdx=contains(rFootNames,eligNames);
the rIdx variable is the same length as rFootNames, as expected, but
sum(rIdx)
comes out to be 36, which is larger than the length of the "eligNames" pat argument, which I thought would be impossible! I think that the correct answer here is 25, which is the number returned by
sum(ismember(rFootNames,eligNames))
How can there be more matches found than elements in "eligNames" when using contains()? Is this expected behavior? What am I missing? Thanks.
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 27 de Oct. de 2021
Editada: Image Analyst
el 27 de Oct. de 2021
0 votos
Because some of the names in eligNames occur in more than one location of rFootNames so they are counted more than once.
1 comentario
Mitchell Tillman
el 27 de Oct. de 2021
Editada: Mitchell Tillman
el 27 de Oct. de 2021
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!