Finding string such as "A**B"

1 vue (au cours des 30 derniers jours)
HCLEE
HCLEE le 3 Fév 2023
Commenté : HCLEE le 3 Fév 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.

Réponse acceptée

Tushar Behera
Tushar Behera le 3 Fév 2023
Modifié(e) : Tushar Behera le 3 Fév 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 commentaire
HCLEE
HCLEE le 3 Fév 2023
Thank you for your help greatly.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by