Matching only parts of two cell arrays

2 visualizaciones (últimos 30 días)
joseph Frank
joseph Frank el 14 de Jul. de 2013
A= {'36450A107';'36467A107';'38067A107'}
B={'36467A'};
How can I find that the 2nd cell in A matches the first 6 characters of B?

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 14 de Jul. de 2013
Editada: Azzi Abdelmalek el 14 de Jul. de 2013
out=find(cellfun(@(x) strcmp(x(1:6),B),A))

Más respuestas (2)

Andrei Bobrov
Andrei Bobrov el 14 de Jul. de 2013
find(~cellfun('isempty',regexp(A,B)));

Chandrasekhar
Chandrasekhar el 14 de Jul. de 2013
for i = 1:length(A)
TF = findstr(char(B(1)),char(A(i)))
if(TF == 1)
disp(i)
end
end
  1 comentario
joseph Frank
joseph Frank el 14 de Jul. de 2013
this is not correct I tried it and it gave TF = 1 and 2 . I think you misunderstood the question. I want to find where the 1st 6 characters in A matches B . the 1st row definitely doesn't match nor the 3rd. the only row that matches is the 2nd one.

Iniciar sesión para comentar.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by