フィルターのクリア

Compare strings of different dimensions

1 回表示 (過去 30 日間)
pamela sulis
pamela sulis 2016 年 4 月 5 日
編集済み: pamela sulis 2016 年 4 月 5 日
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?

採用された回答

KSSV
KSSV 2016 年 4 月 5 日
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 件のコメント
pamela sulis
pamela sulis 2016 年 4 月 5 日
編集済み: pamela sulis 2016 年 4 月 5 日
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?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by