Logical indexing in cell array
Mostrar comentarios más antiguos
Is there a way to search strings in a cell array similar to numeric arrays?
a = [1 2 3 4 5 6];
>> idx = find(a==3)
idx = 3
>> b = {'1' '2' '3' '4' '5' '6'};
>> idx = find(b=='3')
Undefined function 'eq' for input arguments of type 'cell'.
Respuesta aceptada
Más respuestas (3)
Ganesh Hegade
el 14 de Oct. de 2016
Hi, You can use this
strcmp(b, '3');
1 comentario
matuser123
el 14 de Oct. de 2016
Sulaymon Eshkabilov
el 4 de Jul. de 2021
Now, what michio suggested works perfectly ok:
b = {'1' '2' '3' '4' '5' '6'};
b(cellfun(@(x) strcmp(x,'3'), b))={'Found 3'}
So this is another good solution for this exercise.
Categorías
Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!