seach string in arraycell and find idx
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
piero
el 18 de Sept. de 2023
Respondida: David Hill
el 18 de Sept. de 2023
C = {'A',31;
'B',5;
'C',3}
idx = find(ismember(C,{'A'}))
0 comentarios
Respuesta aceptada
David Hill
el 18 de Sept. de 2023
C = {'A',31;
'B',5;
'C',3};
idx = find(ismember(C(:,1),{'A'}))
0 comentarios
Más respuestas (1)
Dyuman Joshi
el 18 de Sept. de 2023
When using ismember, if any of the input is a Cell array, it is expected that it will be a cell array of character vectors.
> which is what the error states
> which is mentioned in the documentation as well - Input Arguments for ismember()
But C is not a homogenueous cell array of character vectors, it has numeric data as well. So the above code does not work.
C = {'A',31;
'B',5;
'C',3}
%Comparing with cell array of character vector
idx = find(strcmp(C,{'A'}))
%Comparing with character
idx = find(strcmp(C,'A'))
%Comparing with string
idx = find(strcmp(C,"A"))
0 comentarios
Ver también
Categorías
Más información sobre String Parsing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!