Compare strings of different dimensions

1 visualización (últimos 30 días)
pamela sulis
pamela sulis el 5 de Abr. de 2016
Editada: pamela sulis el 5 de Abr. de 2016
Hi! I have the string s1 and s2
s1={'1' '631' '618' '574' '678'}
s2={'1' '596' '674' '' '';'674' '631' '1' '631' '1';'641' '617' '674' '631' '654';'674' '673' '674' '673' '674';'674' '618' '1' '618' '631';'631' '1' '631' '674' '740';'739' '740' '733' '674' '631';'674' '673' '674' '1' '641';'618' '1' '631' '618' '631';'674' '631' '618' '631' '618';'674' '631' '1' '631' '625';'641' '642' '618' '631' '618';'618' '631' '1' '631' '1'}
I want to compare s1 and its substrings
{'1'}
{'1' '631'}
{'1' '631' '618'}
{'1' '631' '618' '574'}
{'1' '631' '618' '574' '678'}
{'631'}
{'631' '618'}
{'631' '618' '574'}
{'631' '618' '574' '678'}
{'618'}
{'618' '574'}
{'618' '574' '678'}
{'574'}
{'574' '678'}
{'678'}
with s2: I have used strcmp(s1,s2) but I don't obtain the expected result. Can you help me?

Respuesta aceptada

KSSV
KSSV el 5 de Abr. de 2016
s1={'1' '631' '618' '574' '678'} ;
s2={'1' '596' '674' '' '';
'674' '631' '1' '631' '1';
'641' '617' '674' '631' '654';
'674' '673' '674' '673' '674';
'674' '618' '1' '618' '631';
'631' '1' '631' '674' '740';
'739' '740' '733' '674' '631';
'674' '673' '674' '1' '641';
'618' '1' '631' '618' '631';
'674' '631' '618' '631' '618';
'674' '631' '1' '631' '625';
'641' '642' '618' '631' '618';
'618' '631' '1' '631' '1'} ;
[m,n] = size(s2) ;
comp = zeros(size(s2)) ;
for i = 1:m
comp(i,:) = strcmp(s1,s2(i,:)) ;
end
Compare each row of s2 with s1.
  1 comentario
pamela sulis
pamela sulis el 5 de Abr. de 2016
Editada: pamela sulis el 5 de Abr. de 2016
thanks! If I wanto to compare s2 with
s3= {'1';'1' '631';'1' '631' '618'; '1' '631' '618' '574'; '1' '631' '618' '574' '678';'631'; '631' '618'; '631' '618' '574'; '631' '618' '574' '678';'618';'618' '574';'618' '574' '678';'574';'574' '678';'678'},
how can modify the code?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings 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!

Translated by