Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Enrica Brunetti
Enrica Brunetti am 9 Sep. 2020
Bearbeitet: Ameer Hamza am 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 Kommentare
KSSV
KSSV am 9 Sep. 2020
How a string and numbers can be present in the array?
Enrica Brunetti
Enrica Brunetti am 9 Sep. 2020
Sorry; I was wrong. It's a char format.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 9 Sep. 2020
Bearbeitet: Ameer Hamza am 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');

Weitere Antworten (1)

KSSV
KSSV am 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

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by