Filter löschen
Filter löschen

Delete letters in a string variable

54 Ansichten (letzte 30 Tage)
Zheng am 31 Mai 2013
Kommentiert: Erfan Askarzadeh am 2 Mär. 2022
for instance, string variables are '2456.00A', '2501A',...
How can I delete letters in a string variable?
Thanks in advance.

Akzeptierte Antwort

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

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 31 Mai 2013
Bearbeitet: Azzi Abdelmalek am 31 Mai 2013
s={'2456.00A', '2501A'};
out=cellfun(@(x) x(regexp(x,'[^a-zA-Z]')),s,'un',0)


Mehr zu Characters and Strings finden Sie in Help Center und File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by