Convert string cell array to string literal

16 次查看(过去 30 天)
fileval = 'xxx_yyy_zzz'
nm1parts = split(fileval,'_');
fpart = '';
for ii = 1:length(nm1parts)
if ii~=length(nm1parts)
%fpart = fpart + string(nm1parts{ii}) + '\'
fpart = strcat(fpart, string(nm1parts{ii}), filesep);
else
%fpart = fpart + string(nm1parts{ii})
fpart = strcat(fpart, string(nm1parts{ii}));
end
end
whos fpart
nmdir = 'C:\Users\train'
mnm0 = [nmdir filesep fpart '.obj']
Here is my code, when I am trying to append to get the file path, it creates string cell array rather than a single string. Please help
output of mnm0- mnm0 =
1×4 string array
"C:\Users\train" "\" "xxx\yyy\zzz" ".obj"
what I want is - 'C:\Users\train\xxx\yyy\zzz.obj"

回答(1 个)

Star Strider
Star Strider 2020-6-22
There are two functions that will do that and the reverse: fullfile and fileparts.

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by