octave 3.2.4 用imread读图像会出现一个找不到文件的错误
在交互命令下输入edit imread 会发现是 file_in_path这个函数返回值为0导致的。然后接着edit file_in_path,出现下边的函数代码
function name=file_in_path(p,file)
idx=[1 findstr(p,pathsep) length(p)+1];for i=1:length(idx)-1
if idx(i+1)-idx(i)<=1, continue; end
dir=p(idx(i)+1:idx(i+1)-1);
name = fullfile(dir, file);
fid = fopen(name,"r");
if fid >= 0,
fclose(fid);
return
end
end
name=[];
用下边的代码替换
再用imread读文件就不会有问题了
function name=file_in_path(p,file)idx=[1 findstr(p,pathsep) length(p)+1];
for i=1:length(idx)-1
if idx(i+1)-idx(i)<=1
dir=strcat(pwd,"/");
else
dir=p(idx(i)+1:idx(i+1)-1);
end
name = fullfile(dir, file);
fid = fopen(name,"r");
if fid >= 0
fclose(fid);
return
end
end
fid = fopen(file,"r");
if fid >= 0,
fclose(fid);
name=file;
return
end
name=[];
ref: