exist() for functions only?

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 Comments

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.
For functions only, this blog post and ensuing comments explains:

Sign in to comment.

 Accepted Answer

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

5 Comments

... but why not just
isempty(which( functionname ))
Without the .m it will not distinguish between functions and variables.
per isakson
per isakson on 20 Dec 2014
Edited: per isakson on 20 Dec 2014
Yes, exactly!
Will this work in a deployed application? since the file isn't actually on the filepath any longer as its packaged in an EXE?
What about p-files?

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 19 Dec 2014
Edited: Azzi Abdelmalek on 19 Dec 2014
exist()==2
%or
A = exist('name','file')

1 Comment

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.

Sign in to comment.

Categories

Asked:

on 19 Dec 2014

Commented:

on 22 Dec 2014

Community Treasure Hunt

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

Start Hunting!