Finding string such as "A**B"

1 visualizzazione (ultimi 30 giorni)
HCLEE
HCLEE il 3 Feb 2023
Commentato: HCLEE il 3 Feb 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.

Risposta accettata

Tushar Behera
Tushar Behera il 3 Feb 2023
Modificato: Tushar Behera il 3 Feb 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

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by