How to compare two strings with different sizes?

15 ビュー (過去 30 日間)
Thi Hong Loc Le
Thi Hong Loc Le 2021 年 3 月 1 日
編集済み: Jan 2021 年 3 月 2 日
Hi everyone,
I would like to make a matrix by comparing 2 sequences with different dimensions, if it's same character (eg: A-A), it will be traced to 1, if not it will be traced to 0.
a = 'AAGCTACGC'
b = 'ACGCAA'
However, I have trouble to make this matrix. Honestly, I am a beginner, hope you guys will help me.
Thanks a lot.
  1 件のコメント
Jan
Jan 2021 年 3 月 1 日
編集済み: Jan 2021 年 3 月 2 日
What do you want to obtain as output for these inputs?

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

採用された回答

Matt J
Matt J 2021 年 3 月 1 日
編集済み: Matt J 2021 年 3 月 1 日
Another guess:
a = 'AAGCTACGC';
b = 'ACGCAA';
match = ( a(:)==b )
match = 9x6 logical array
1 0 0 0 1 1 1 0 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0 0
  1 件のコメント
Thi Hong Loc Le
Thi Hong Loc Le 2021 年 3 月 1 日
I got it. Thank you

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

その他の回答 (1 件)

Jan
Jan 2021 年 3 月 1 日
A bold guess:
a = 'AAGCTACGC'
b = 'ACGCAA'
Nmin = min(numel(a), numel(b));
Nmax = max(numel(a), numel(b));
match = false(1, Nmax);
match(1:Nmin) = (a(1:Nmin) == b(1:Nmin));

カテゴリ

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