Check for missing object in workspace
9 次查看(过去 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!