How to compare two strings with different sizes?

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개)

Jan
Jan 2021년 3월 1일

0 개 추천

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));

카테고리

질문:

2021년 3월 1일

편집:

Jan
2021년 3월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by