how to get the string inside exist ?

1 回表示 (過去 30 日間)
Rakesh Praveen
Rakesh Praveen 2013 年 8 月 9 日
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');
%%%%%%%%%

採用された回答

kjetil87
kjetil87 2013 年 8 月 9 日
exist([num2str(val),'.png'],'file')
  2 件のコメント
kjetil87
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.
Rakesh Praveen
Rakesh Praveen 2013 年 8 月 9 日
actually there are 1000s of .png files named numerically in a directory. one of the file in between got renamed accidentally. Now i do not know the original name of this renamed file. so i thought i will run the 'for' loop and when the missing file number turns up, 'exist' will return a zero and the loop breaks and that is the location of this renamed file.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by