As I understand, the exist() function in MATLAB will return "2" if the input is a MATLAB function.
The list of options for the second input 'kind' are builtin, class, dir, file, and var.
I want to input 'kind' so that exist() will ONLY search for functions, and return 2 if it is a match to a function and a 0 if not.
Is there any way to do this?

2 件のコメント

Sean de Wolski
Sean de Wolski 2014 年 12 月 22 日
So you mean ONLY functions or any MATLAB files that will run (scripts/functions/classes)? which will return something for scripts and classes as well.
Sean de Wolski
Sean de Wolski 2014 年 12 月 22 日
For functions only, this blog post and ensuing comments explains:

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

 採用された回答

matt dash
matt dash 2014 年 12 月 19 日

2 投票

An option that is not exactly what you describe, but might work for you:
isempty(which([functionname,'.m']))

5 件のコメント

per isakson
per isakson 2014 年 12 月 20 日
... but why not just
isempty(which( functionname ))
matt dash
matt dash 2014 年 12 月 20 日
Without the .m it will not distinguish between functions and variables.
per isakson
per isakson 2014 年 12 月 20 日
編集済み: per isakson 2014 年 12 月 20 日
Yes, exactly!
Daniel
Daniel 2014 年 12 月 22 日
Will this work in a deployed application? since the file isn't actually on the filepath any longer as its packaged in an EXE?
Sean de Wolski
Sean de Wolski 2014 年 12 月 22 日
What about p-files?

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 12 月 19 日
編集済み: Azzi Abdelmalek 2014 年 12 月 19 日

0 投票

exist()==2
%or
A = exist('name','file')

1 件のコメント

Daniel
Daniel 2014 年 12 月 19 日
My problem here is what if it exists as a workspace variable or another non-m file on the search path? in that case it will return 1 or 5 respectively, while I would still not be sure if it exists as a funciton.

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

カテゴリ

ヘルプ センター および File ExchangeFile Operations についてさらに検索

質問済み:

2014 年 12 月 19 日

コメント済み:

2014 年 12 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by