필터 지우기
필터 지우기

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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by