フィルターのクリア

How to check the existence of a non-existent handle

25 ビュー (過去 30 日間)
klaus ebert
klaus ebert 2015 年 5 月 29 日
コメント済み: Chandan Prakash 2020 年 7 月 8 日
Hello everyone,
is there any way to check if a handle exists or not? So something like: if I didnt previously declare a handle, I want a 0 as output and else a 1.
I tried ishandle,isvalid,isfield,isempty but they all don't work on a "non-existent field" so I receive an error if I didnt declare the handle.. "Reference to non-existent field 'SP'."
If I try the "exist name" function it just works for variables but not for handles
So:
handle.a=figure;
exist handle.a;
returns a 0 (dont know why since the next codepart is working so handle.a strictly speaking has to exist)
while
handle.a=figure;
a=handle.a;
exist a
returns a 1
but I'm looking for something like:
handle.a=figure;
exist handle.a
ans=1
%without setting the handle:
exist handle.a
ans=0
I hope my post is understandable. Thank you for your help! Klaus

採用された回答

Titus Edelhofer
Titus Edelhofer 2015 年 5 月 29 日
Hi Klaus,
I guess
isfield(handle, 'a') && ishandle(handle.a)
is what you are looking for ...?
Titus
  5 件のコメント
klaus ebert
klaus ebert 2015 年 5 月 29 日
eval() is what I was looking for. Thank you both alot!
Chandan Prakash
Chandan Prakash 2020 年 7 月 8 日
Thank you...!!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by