Convert string cell array to string literal

16 views (last 30 days)
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"

Answers (1)

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

Categories

Find more on File Operations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!