Compare strings of different dimensions
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
pamela sulis
am 5 Apr. 2016
Bearbeitet: pamela sulis
am 5 Apr. 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?
0 Kommentare
Akzeptierte Antwort
KSSV
am 5 Apr. 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 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!