Borrar filtros
Borrar filtros

is there a more efficient way to omit certain characters from a string without using loops?

1 visualización (últimos 30 días)
Hello. I have to take out characters from a string. I am using strrep. :
newsf = strrep(sf, 'C', '');
newsf = strrep(newsf, 'R', ''); n ewsf = strrep(newsf, 'E', '');
newsf = strrep(newsf, 'P', ''); newsf = strrep(newsf, 'SQ', '');
newsf = strrep(newsf, '1', '');
newsf = strrep(newsf, '2', '');
newsf = strrep(newsf, '3', '');
newsf = strrep(newsf, '4', '');
etc
I have tried using ~= for the characters I want but it won't accept that. Thanks for your time

Respuesta aceptada

Cedric
Cedric el 2 de Mayo de 2013
Editada: Cedric el 2 de Mayo de 2013
One way would be
newsf = regexprep(sf, '([CREP1-4]|SQ)', '') ;
but what does "etc" encompass?
  2 comentarios
Brian
Brian el 2 de Mayo de 2013
Thank you sir, that's brilliant. Sorry, I meant the rest of possible numeric values. 0-9 worked, thanks again

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by