文件标识符无效。使用 fopen 生成有效的文件标识符
Invalid file identifier. Use fopen to generate a valid file identifier
我正在尝试使用 textscan
读取一系列文件,但我不断收到此错误:
Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
我的代码是:
fd = fopen(['D:\Thesis\Data\vedai_co_75_25\train\labels\' files(id).name],'rt');
line = textscan(fd, '%s %f %d %f %f %f %f %f %f %f %f %f %f %f %f');
当我尝试查看 ['D:\Thesis\Data\vedai_co_75_25\train\labels\' files(id).name]
的输出时,它 returns 路径正确:
D:\Thesis\Data\vedai_co_75_25\train\labels[=16=]000000.png
也可以命令 fopen(D:\Thesis\Data\vedai_co_75_25\train\labels[=13=]000000.png)
returns 3 或 4 等等
但是命令fopen(['D:\Thesis\Data\vedai_co_75_25\train\labels\' files(id).name])
returns-1。
我怎样才能使这个工作?
问题可能是您试图以文本模式打开 .png 文件。
尝试 fd = fopen( file_name, 'r')
,或者在您的示例中:
fd = fopen(['D:\Thesis\Data\vedai_co_75_25\train\labels\' files(id).name],'r');
在 Windows,以文本模式打开错误的文件可能会导致问题。 fopen
的帮助指出:
(On Unix, text and
binary mode are the same, so this has no effect. On PC systems
this is critical.)
我正在尝试使用 textscan
读取一系列文件,但我不断收到此错误:
Error using textscan Invalid file identifier. Use fopen to generate a valid file identifier.
我的代码是:
fd = fopen(['D:\Thesis\Data\vedai_co_75_25\train\labels\' files(id).name],'rt');
line = textscan(fd, '%s %f %d %f %f %f %f %f %f %f %f %f %f %f %f');
当我尝试查看 ['D:\Thesis\Data\vedai_co_75_25\train\labels\' files(id).name]
的输出时,它 returns 路径正确:
D:\Thesis\Data\vedai_co_75_25\train\labels[=16=]000000.png
也可以命令 fopen(D:\Thesis\Data\vedai_co_75_25\train\labels[=13=]000000.png)
returns 3 或 4 等等
但是命令fopen(['D:\Thesis\Data\vedai_co_75_25\train\labels\' files(id).name])
returns-1。
我怎样才能使这个工作?
问题可能是您试图以文本模式打开 .png 文件。
尝试 fd = fopen( file_name, 'r')
,或者在您的示例中:
fd = fopen(['D:\Thesis\Data\vedai_co_75_25\train\labels\' files(id).name],'r');
在 Windows,以文本模式打开错误的文件可能会导致问题。 fopen
的帮助指出:
(On Unix, text and binary mode are the same, so this has no effect. On PC systems this is critical.)