Borrar filtros
Borrar filtros

Finding string such as "A**B"

1 visualización (últimos 30 días)
HCLEE
HCLEE el 3 de Feb. de 2023
Comentada: HCLEE el 3 de Feb. de 2023
Hi,
Is there any way to find word uncontinous such as "A**B" in matrix?
Here the example,
AGDB
ARBC
AGRB
ATWC
AWYB
I want to find 'AGDB', 'AGRB', 'AWYB' which are have same regularity 'A**B'.
Please help me.
Thank you.

Respuesta aceptada

Tushar Behera
Tushar Behera el 3 de Feb. de 2023
Editada: Tushar Behera el 3 de Feb. de 2023
Hi HCLEE,
I believe you want to find a string in your matrix which have starting point as "A" and ending with "B".
This can be acheived by using "regexp" function in matlab. For example:
matrix = {'AGDB', 'ARBC', 'AGRB', 'ATWC', 'AWYB','DAmnnB'};
expression = '^A.*B$';
indices = cellfun(@(x) ~isempty(regexp(x, expression, 'start')), matrix);
result = matrix(indices);
In this code, the "cellfun" function is used to apply the regexp function to each element of the cell array matrix. "cellfun" is a function in MATLAB that applies a function to each element of a cell array, and returns the results as an array of the same size.
i hope this resolves your query.
Regards,
Tushar
  1 comentario
HCLEE
HCLEE el 3 de Feb. de 2023
Thank you for your help greatly.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by