フィルターのクリア

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

3 ビュー (過去 30 日間)
Enrica Brunetti
Enrica Brunetti 2020 年 9 月 9 日
編集済み: Ameer Hamza 2020 年 9 月 9 日
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 件のコメント
KSSV
KSSV 2020 年 9 月 9 日
How a string and numbers can be present in the array?
Enrica Brunetti
Enrica Brunetti 2020 年 9 月 9 日
Sorry; I was wrong. It's a char format.

サインインしてコメントする。

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 9 月 9 日
編集済み: Ameer Hamza 2020 年 9 月 9 日
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');

その他の回答 (1 件)

KSSV
KSSV 2020 年 9 月 9 日
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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by