create a .txt file in a specific folder
16 次查看(过去 30 天)
显示 更早的评论
normally i use this:
mkdir('xxxx')
filename = ['xxxx\',FileName,'.txt'];"
to build the file name
and now the xxxx is variable so i can't do this 'xxxx\' any more, so how can i resolve this problem ? thank YOU!
0 个评论
回答(1 个)
Stephen23
2015-7-16
编辑:Stephen23
2015-7-17
dir_path = 'my_project_directory';
file_name = 'test1.txt';
mkdir(dir_path);
out = fullfile(dir_path,file_name)
Note that you do not need to specify any path separator characters as these are inserted by fullfile automatically (and of the correct type to match your OS).
Similarly it is also more reliable to build a filename using sprintf rather than string concatenation, e.g. to generate the above filename:
file_name = sprintf('test%d.txt',1);
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!