使用 matlab 创建一个新的空白 .txt 文件
creating a new blank .txt file using matlab
如何创建一个空白的 .txt 文件?我使用 Matlab R2014a.
我想检查指定名称的文件是否存在,如果不存在,我想创建一个。
我不喜欢只回答 "ask" 而没有提供 "I tried this..." 的问题。
不过,有很多方法可以完成您的要求。这是其中之一:
if exist('text.txt', 'file') == 0
disp('File does not exist, creating file.')
f = fopen( 'text.txt', 'w' );
fclose(f);
else
disp('File exists.');
end
检查文件是否存在,只需使用exist
命令:
exist( filename, 'file' )
要创建一个空文件,您可以简单地使用 fopen
and fclose
:
if ~exist(filename, 'file' )
fid = fopen(filename,'w');
fclose(fid);
end
如何创建一个空白的 .txt 文件?我使用 Matlab R2014a.
我想检查指定名称的文件是否存在,如果不存在,我想创建一个。
我不喜欢只回答 "ask" 而没有提供 "I tried this..." 的问题。
不过,有很多方法可以完成您的要求。这是其中之一:
if exist('text.txt', 'file') == 0
disp('File does not exist, creating file.')
f = fopen( 'text.txt', 'w' );
fclose(f);
else
disp('File exists.');
end
检查文件是否存在,只需使用exist
命令:
exist( filename, 'file' )
要创建一个空文件,您可以简单地使用 fopen
and fclose
:
if ~exist(filename, 'file' )
fid = fopen(filename,'w');
fclose(fid);
end