How do you add a file extension when creating a file based on function input?
11 ビュー (過去 30 日間)
古いコメントを表示
I want to be able to use an input for a function and create a text file based on the fid. The strjoin() function always inputs a space in between the fid and the '.txt'. This is what I have now, but I need a more optimal method.
function[...] = name(fid)
textfile = strjoin({fid,'.txt'})
end
The output would then look like 'fid .txt'. I need to have the space removed. Is there any better function than using strjoin()?
0 件のコメント
採用された回答
Star Strider
2015 年 4 月 12 日
I’m not certain what you want (because I don’t know what ‘fid’ is), but see if:
textfile = [fid,'.txt'];
does what you want.
Example:
fid = 'FileNamePrefix';
textfile = [fid,'.txt']
produces:
textfile =
FileNamePrefix.txt
3 件のコメント
Image Analyst
2015 年 4 月 12 日
An alternate way, useful for when the filenames are really complicated
textfile = sprintf('%s.txt', fid);
Note that fid is the variable name commonly given to the output of fopen() and not to the base file name string, so I recommend you choose a different name for the fid variable, like, how about baseFileName?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!