Parse cell array into separate cells, with no delimiter
古いコメントを表示
Hello! I am trying to parse the name of a file into separate variables to describe the file, but there are no delimiters in the file name. For example, if my file name is
fileName = {'11171401'}
I want to divide this into:
track = {'1117'}
cycle = {'14'}
segment = {'01'}
I've already chopped off the beginning of the file name using the split function, but I can't seem to figure out how to divide up the rest without a delimiter. Thank you in advance for any help!
6 件のコメント
James Tursa
2022 年 7 月 7 日
What are the rules for the name splitting? If it is always 4-2-2 character splits then you could just use indexing.
Gabrielle Trudeau
2022 年 7 月 7 日
編集済み: Gabrielle Trudeau
2022 年 7 月 7 日
Gabrielle Trudeau
2022 年 7 月 7 日
per isakson
2022 年 7 月 7 日
In your solution, track, cycle and segment are all double, not cells containing character vectors as required. Try
fileName = {'11171401'};
track = {fileName{1}(1:4)}
cycle = {fileName{1}(5:6)}
segment = {fileName{1}(7:8)}
Gabrielle Trudeau
2022 年 7 月 8 日
fnm = {'11171401'; '22282512'; '33393623'};
tkn = regexp(fnm,'^(\d{4})(\d\d)(\d\d)$','tokens','once');
tkn = vertcat(tkn{:})
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!