フィルターのクリア

Remove zeros in a table?

15 ビュー (過去 30 日間)
Laurie Gerstenberger
Laurie Gerstenberger 2020 年 6 月 8 日
Hey everyone,
I am having the following problem which I am struggling with for quite some time. I have a character array of strings - each consisting of two numbers and an underscore. (e.g. 09_13, 14_15, 08_07). In this format I can use them as a column in a table. However, preferably I would like to save the table as an xls sheet and remove all zeros (e.g 9_13,14_15,8_7). This way the entry length in each row would differ obviously. Is that even possible in a table?
Thanks
Laurie

採用された回答

Walter Roberson
Walter Roberson 2020 年 6 月 8 日
regexprep(YourCellArray, {'^0+(?=\d)', '(?<=_)0+(?=\d)'}, {'', ''})
This takes care not to replace an all-zero sequence with emptiness -- e.g., '00_14' will be converted to '0_14' and not '_14'. The code can be simplified a little if it is certain that a string of all 0 will not be present.
The code does not assume that the values are 2 digit; the code could be simplified even more if it was certain that all values were 2 digit.
regexprep(YourCellArray, {'^0', '_0'}, {'', '_'}) %2 digit case only
  1 件のコメント
Laurie Gerstenberger
Laurie Gerstenberger 2020 年 6 月 8 日
Great--thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by