how to get the string inside exist ?
1 次查看(过去 30 天)
显示 更早的评论
Hi, I wanted to search the file names sequentially inside a directory (Note:I haven't included its logic here). Right now my concern is how to read the string '1.png' inside the command 'exist'. so that fname will return a 0 or 2. Thank you.
%%%%%%%%%
val=1;
tmp=strcat(num2str(val),{'.png'});
% now how do i read this tmp inside exist. when i tried as shown below, i get: Undefined function 'exist' for input arguments of type 'cell'.
fname=exist(strcat(num2str(val),{'.png'}),'file');
%%%%%%%%%
0 个评论
采纳的回答
kjetil87
2013-8-9
exist([num2str(val),'.png'],'file')
2 个评论
kjetil87
2013-8-9
编辑:kjetil87
2013-8-9
the error you get is because you put .png inside a cell. You can also use strcat as you did but remove
{}
Also i find it weird that you call the output of exist fname, the return of exist(...,'file') is just a number indicating what type of file see help exist , or 0 if the file is not found.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!