Check for missing object in workspace
8 ビュー (過去 30 日間)
古いコメントを表示
In a script, how do I check to see whether an object (array) exists before I try to operate on it. Something like:
if object exists then
0 件のコメント
回答 (2 件)
Image Analyst
2011 年 8 月 11 日
From the help for "exist()":
The following example indicates that testresults is both a variable in the workspace and a folder on the search path:
exist('testresults','var')
ans =
1
exist('testresults','dir')
ans =
7
0 件のコメント
Stephen
2011 年 8 月 11 日
2 件のコメント
Image Analyst
2011 年 8 月 11 日
I was just going to say that. That's a very common mistake. No you can't delete the string - otherwise exist() would have no arguments whatsoever that you're passing in. You have to pass in something.
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!