How to compare two strings with different sizes?

13 visualizaciones (últimos 30 días)
Thi Hong Loc Le
Thi Hong Loc Le el 1 de Mzo. de 2021
Editada: Jan el 2 de Mzo. de 2021
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 comentario
Jan
Jan el 1 de Mzo. de 2021
Editada: Jan el 2 de Mzo. de 2021
What do you want to obtain as output for these inputs?

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 1 de Mzo. de 2021
Editada: Matt J el 1 de Mzo. de 2021
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

Más respuestas (1)

Jan
Jan el 1 de Mzo. de 2021
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));

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by