フィルターのクリア

Finding string such as "A**B"

5 ビュー (過去 30 日間)
HCLEE
HCLEE 2023 年 2 月 3 日
コメント済み: HCLEE 2023 年 2 月 3 日
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.

採用された回答

Tushar Behera
Tushar Behera 2023 年 2 月 3 日
編集済み: Tushar Behera 2023 年 2 月 3 日
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 件のコメント
HCLEE
HCLEE 2023 年 2 月 3 日
Thank you for your help greatly.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by