Azzera filtri
Azzera filtri

exist() for functions only?

2 visualizzazioni (ultimi 30 giorni)
Daniel
Daniel il 19 Dic 2014
Commentato: Sean de Wolski il 22 Dic 2014
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 Commenti
Sean de Wolski
Sean de Wolski il 22 Dic 2014
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 il 22 Dic 2014
For functions only, this blog post and ensuing comments explains:

Accedi per commentare.

Risposta accettata

matt dash
matt dash il 19 Dic 2014
An option that is not exactly what you describe, but might work for you:
isempty(which([functionname,'.m']))
  5 Commenti
Daniel
Daniel il 22 Dic 2014
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 il 22 Dic 2014
What about p-files?

Accedi per commentare.

Più risposte (1)

Azzi Abdelmalek
Azzi Abdelmalek il 19 Dic 2014
Modificato: Azzi Abdelmalek il 19 Dic 2014
exist()==2
%or
A = exist('name','file')
  1 Commento
Daniel
Daniel il 19 Dic 2014
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.

Accedi per commentare.

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by