如何在Matlab中的子文件夹中创建文件

How to create a file in a subfolder in Matlab

我正在尝试在 Matlab 的子文件夹中使用 fopen 创建一个文件。

在我的项目目录中有一个文件夹 'logs' 所以我尝试了这个:

filename = 'log.txt';
date_format = 'mmm_dd_yyyy_HH:MM';
time_stamp = datestr(now, date_format);
file2 = fullfile('logs', strcat(time_stamp, filename));
fid = fopen(file2, 'w');

我收到错误:

The file name contains characters that are not contained in the filesystem encoding. Certain operations may not work as expected.

我认为这是格式问题,但我不知道哪里出了问题。

编辑:以防万一... Windows 7 和 Matlab R2016a

删除冒号 (:)。

date_format = 'mmm_dd_yyyy_HH_MM';

在 windows 中,文件名不能包含 /:*"<> 和 ? 标记。