Delete letters in a string variable

88 visualizaciones (últimos 30 días)
Zheng
Zheng el 31 de Mayo de 2013
Comentada: Erfan Askarzadeh el 2 de Mzo. de 2022
Hi,
for instance, string variables are '2456.00A', '2501A',...
How can I delete letters in a string variable?
Thanks in advance.

Respuesta aceptada

Jonathan Sullivan
Jonathan Sullivan el 31 de Mayo de 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

Más respuestas (1)

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

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by