Replacing special character 'É' to 'E'
Mostrar comentarios más antiguos
Hi,
Is there a Matlab function to replace the special characters (like 'É') to the regular UTF-8 or ISO-8859-1?
Thanks,
1 comentario
Stephen23
el 28 de Nov. de 2022
"regular UTF-8 or ISO-8859-1"
Both UTF-8 (encodes all Unicode characters) and ISO-8859-1 include "É"... Perhaps you meant to ask something like "how to remove diacritics from characters?", which would match your question title.
Respuesta aceptada
Más respuestas (2)
"Is there a Matlab function to replace the special characters (like 'É')"
You can call Python from MATLAB, and it can do the heavy-lifting:
inp = 'É';
baz = @(v)char(v(1)); % only need the first decomposed character.
out = baz(py.unicodedata.normalize('NFKD',inp)) % to remove diacritics.
Read more:
John D'Errico
el 28 de Nov. de 2022
Editada: John D'Errico
el 28 de Nov. de 2022
Easy peasy.
str = 'ABCDEFGHIJKÉÉÀÀÄÄabcdefghijkl'
strrep(str,'É','E')
If there are other special characters you want replaced, strrep will handle them too, but it looks like you would need to do them one at a time with strrep. But other tools would certainly work too. Certainly regexp, but I've never been very good at regular expressions. :) This will work though:
badchar = 'ÉÀÄ';
goodchar = 'EAA';
[u,v] = ismember(str,'ÉÀÄ');
str(u) = goodchar(v(u))
1 comentario
Robert Wagner
el 12 de Dic. de 2023
but I've never been very good at regular expressions. :) ---> I've never tried to be in the first place... :-)))
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!