Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Enrica Brunetti
Enrica Brunetti le 9 Sep 2020
Modifié(e) : Ameer Hamza le 9 Sep 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 commentaires
KSSV
KSSV le 9 Sep 2020
How a string and numbers can be present in the array?
Enrica Brunetti
Enrica Brunetti le 9 Sep 2020
Sorry; I was wrong. It's a char format.

Connectez-vous pour commenter.

Réponse acceptée

Ameer Hamza
Ameer Hamza le 9 Sep 2020
Modifié(e) : Ameer Hamza le 9 Sep 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');

Plus de réponses (1)

KSSV
KSSV le 9 Sep 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

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!

Translated by