MATLAB: Compare strings of different dimensions

comparestrcmpstrings

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?

Best Answer

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.