MATLAB if exist([img_path num2str(1, '%04i.png')], 'file'),
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MATLAB if exist([img_path num2str(1, '%04i.png')], 'file'),相关的知识,希望对你有一定的参考价值。
img_files = num2str((1:seq.len)', [img_path '%04i.png']);
elseif exist([img_path num2str(1, '%04i.jpg')], 'file'),
img_files = num2str((1:seq.len)', [img_path '%04i.jpg']);
elseif exist([img_path num2str(1, '%04i.bmp')], 'file'),
img_files = num2str((1:seq.len)', [img_path '%04i.bmp']);
else
error('No image files to load.')
end
这段代码什么意啊
需要注意的是,img_path中如果包含多层目录,则分隔符应使用“\\”或“/”,而不能使用“\”。 参考技术A 读取img_path目录下的图像文件名
matlab中的exist是啥意思
exist用来判断变量或函数是否存在:
exist Check if variables or functions are defined.exist('A') returns:
0 if A does not exist
1 if A is a variable in the workspace
2 if A is an M-file on MATLAB's search path. It also returns 2 when
A is the full pathname to a file or when A is the name of an
ordinary file on MATLAB's search path
3 if A is a MEX-file on MATLAB's search path
4 if A is a Simulink model or library file on MATLAB's search path
5 if A is a built-in MATLAB function
6 if A is a P-file on MATLAB's search path
7 if A is a directory
8 if A is a class (exist returns 0 for Java classes if you
start MATLAB with the -nojvm option.)
exist('A') or exist('A.EXT') returns 2 if a file named 'A' or 'A.EXT'
and the extension isn't a P or MEX function extension.
exist('A','var') checks only for variables.
exist('A','builtin') checks only for built-in functions.
exist('A','file') checks for files or directories.
exist('A','dir') checks only for directories.
exist('A','class') checks only for classes.
If A specifies a filename, MATLAB attempts to locate the file,
examines the filename extension, and determines the value to
return based on the extension alone. MATLAB does not examine
the contents or internal structure of the file.
When searching for a directory, MATLAB finds directories that are part
of MATLAB's search path. They can be specified by a partial path. It
also finds the current working directory specified by a partial path,
and subdirectories of the current working directory specified by
a relative path.
exist returns 0 if the specified instance isn't found. 参考技术A 检查变量或函数是否被定义 返回0是没有定义 返回1是存在定义在workspace里面 参考技术B >> help exist
EXIST Check if variables or functions are defined.
EXIST('A') returns:
0 if A does not exist
1 if A is a variable in the workspace
2 if A is an M-file on MATLAB's search path. It also returns 2 when
A is the full pathname to a file or when A is the name of an
ordinary file on MATLAB's search path
3 if A is a MEX-file on MATLAB's search path
4 if A is a MDL-file on MATLAB's search path
5 if A is a built-in MATLAB function
6 if A is a P-file on MATLAB's search path
7 if A is a directory
8 if A is a Java class
>> exist('map')
ans =
7
7 if A is a directory
本回答被提问者和网友采纳
以上是关于MATLAB if exist([img_path num2str(1, '%04i.png')], 'file'),的主要内容,如果未能解决你的问题,请参考以下文章
File "C: MATLAB7work mischouse. tiff”does not exist.
PCA图像识别时出现File "d:\matlab\work\ts21\1.jpg" does not exist.的错误