How to remove numbers between specific symbols in text array?
5 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone,
I have a question regarding how to modify a text array in Matlab which contains numbers between two "_" symbols. Here some examples:
- If the string has the following structure: "Gas_1_O2" I expect the following result: "Gas_O2". This should work for every number between two "_" symbols.
- If the string has another structure nothing should happen (e.g. "Time" or "Flow_Fluidization").
The text string will later on be used for renaming a table.
I tried with the function extractBetween but it did not worked as I expected.
Thanks for your support.
Best,
Joseba
0 件のコメント
採用された回答
madhan ravi
2019 年 2 月 14 日
a="Gas_1_O2";
regexprep(a,'\_\d*.?\d*\_','_')
5 件のコメント
Stephen23
2019 年 2 月 14 日
"The code was put keeping only numbers (including decimals)..."
Remember that . by itself matches all characters, not just the decimal point / period chraacter.
madhan ravi
2019 年 2 月 14 日
編集済み: madhan ravi
2019 年 2 月 14 日
True Stephen that‘s why I used [\.] to preserve dot character in the latter comment.
その他の回答 (2 件)
Rik
2019 年 2 月 14 日
You can use regular expressions for this task:
str1='Gas_1_O2';
str2='Flow_Fluidization';
regexprep(str1,'_[0-9]*_','_')
regexprep(str2,'_[0-9]*_','_')
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!