How to delete a value and the value next to it?

1 visualización (últimos 30 días)
Enrica Brunetti
Enrica Brunetti el 9 de Sept. de 2020
Editada: Ameer Hamza el 9 de Sept. de 2020
I want to delete 'S' elements and the number next to them in this char format
f = 'S 0 92 -707 1349 92 -708 1348 92 -708 1348 92 -709 1347 92 -709 1347 93 -710 1347 93 -711 1347 93 -711 1346 S -712 1346 94 -712 1346 94 -713 1345 95 -714 1345 95 -714 1344 95 -715 1344 96 -715 1344 96 -715 1343 S -716 1343 96 -716 1343 96 -716 1343 96 -716 1343 96 -716 1343 96 -716 1343 96 -716 1343 96 -716 1344 96 -715 1344 96 -715 S 95 -715 1344 95 -714 1345 95 -714 1345'
To delete the 'S' I have used this code:
angles = sscanf(strrep(f,'S',''),'%d');
But I don't know to delete the element next to 'S' elements.
  2 comentarios
KSSV
KSSV el 9 de Sept. de 2020
How a string and numbers can be present in the array?
Enrica Brunetti
Enrica Brunetti el 9 de Sept. de 2020
Sorry; I was wrong. It's a char format.

Iniciar sesión para comentar.

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 9 de Sept. de 2020
Editada: Ameer Hamza el 9 de Sept. de 2020
Try regexprep()
f = 'S 0 92 -707 1349 92 -708 1348 92 -708 1348 92 -709 1347 92 -709 1347 93 -710 1347 93 -711 1347 93 -711 1346 S -712 1346 94 -712 1346 94 -713 1345 95 -714 1345 95 -714 1344 95 -715 1344 96 -715 1344 96 -715 1343 S -716 1343 96 -716 1343 96 -716 1343 96 -716 1343 96 -716 1343 96 -716 1343 96 -716 1343 96 -716 1344 96 -715 1344 96 -715 S 95 -715 1344 95 -714 1345 95 -714 1345';
angles = sscanf(regexprep(f, 'S\s(-)*[0-9]*', ''), '%d');

Más respuestas (1)

KSSV
KSSV el 9 de Sept. de 2020
f = 'S 0 92 -707 1349 92 -708 1348 92 -708 1348 92 -709 1347 92 -709 1347 93 -710 1347 93 -711 1347 93 -711 1346 S -712 1346 94 -712 1346 94 -713 1345 95 -714 1345 95 -714 1344 95 -715 1344 96 -715 1344 96 -715 1343 S -716 1343 96 -716 1343 96 -716 1343 96 -716 1343 96 -716 1343 96 -716 1343 96 -716 1343 96 -716 1344 96 -715 1344 96 -715 S 95 -715 1344 95 -714 1345 95 -714 1345' ;
s = strsplit(f) ;
s(1:2) = [] ; % delete the first two cells/ elements
f = strjoin(s) ; % join them back into a char

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by