Delete letters in a string variable
32 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Zheng
le 31 Mai 2013
Commenté : Erfan Askarzadeh
le 2 Mar 2022
Hi,
for instance, string variables are '2456.00A', '2501A',...
How can I delete letters in a string variable?
Thanks in advance.
0 commentaires
Réponse acceptée
Jonathan Sullivan
le 31 Mai 2013
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
Plus de réponses (1)
Azzi Abdelmalek
le 31 Mai 2013
Modifié(e) : Azzi Abdelmalek
le 31 Mai 2013
s={'2456.00A', '2501A'};
out=cellfun(@(x) x(regexp(x,'[^a-zA-Z]')),s,'un',0)
0 commentaires
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!