Convert cell array to character array including string manipulation
4 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I have a n*1 cell array where each value is a combination of drive letter, folder path and file name and file extension such as:
{'C:TEMP\filename1.ext'}
{'C:TEMP\filename2.ext'}
{'C:TEMP\filename3.ext'}
...
Each row has a unique file name as shown above.
Now I would like to convert this cell array into a character array where each string is reduced to the file name only withouth path and file extension:
'filename1'
'filename2'
'filename3'
...
Does anybody know how to accomplish this?
Best regards,
Florian
0 件のコメント
採用された回答
madhan ravi
2019 年 1 月 20 日
R=cell(size(s)); % s is your cell array
for k=1:numel(s)
S=strsplit(s{k},{'\','.'});
R{k}=S{2};
end
Result=string(R)
0 件のコメント
その他の回答 (1 件)
madhan ravi
2019 年 1 月 20 日
Simpler:
R=regexp(s,'(?<=\\)\w+(?=[.])','match'); % s is your cell array
Result=string(R)
2 件のコメント
madhan ravi
2019 年 1 月 20 日
編集済み: madhan ravi
2019 年 1 月 20 日
What do you mean ? see the example below:
s=cell(3,1);
s{1}='C:TEMP\filename1.ext';
s{2}='C:\TEMP\filename2.ext';
s{3}='C:TEMP\filename3.ext';
R=regexp(s,'(?<=\\)\w+(?=[.])','match');
Result=string(R)
Gives:
Result =
3×1 string array
"filename1"
"filename2"
"filename3"
参考
カテゴリ
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!