How to use exist for a cell?
조회 수: 27 (최근 30일)
이전 댓글 표시
Hello,
I have a cell with string elements and I am trying to check if they exist as variables:
A={'B0','B01','B04'}
for i=1:3
if exist(A(i,1),'var')==1
...
This does not work so what do I do? Thx!
댓글 수: 0
채택된 답변
Walter Roberson
2012년 4월 12일
if exist(A{i,1},'var')
Notice the {} instead of ()
댓글 수: 3
Shamir Alavi
2012년 12월 7일
It doesn't work for me! Here's the code:
>> h = {1,2;3,4};
>> exist('h','var')
ans =
1
>> exist('h{1}','var')
ans =
0
>> exist('h{1,1}','var')
ans =
0
Am I making any mistake? If not, is there any other way to check existence of different elements in a cell array?
Thanks
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!