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!