Delete letters in a string variable

조회 수: 89 (최근 30일)
Zheng
Zheng 2013년 5월 31일
댓글: Erfan Askarzadeh 2022년 3월 2일
Hi,
for instance, string variables are '2456.00A', '2501A',...
How can I delete letters in a string variable?
Thanks in advance.

채택된 답변

Jonathan Sullivan
Jonathan Sullivan 2013년 5월 31일
To detect which charectors are letters, you can use the function isletter. Then just simply delete the ones that are letters
Example:
yourString = '2456.00A';
deleteMe = isletter(yourString); % Detect which ones are letters
yourString(deleteMe) = []; % Delete the letters
disp(yourString) % Display the result

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 31일
편집: Azzi Abdelmalek 2013년 5월 31일
s={'2456.00A', '2501A'};
out=cellfun(@(x) x(regexp(x,'[^a-zA-Z]')),s,'un',0)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by