exist() for functions only?

조회 수: 2 (최근 30일)
Daniel
Daniel 2014년 12월 19일
댓글: Sean de Wolski 2014년 12월 22일
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일
An option that is not exactly what you describe, but might work for you:
isempty(which([functionname,'.m']))
  댓글 수: 5
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일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by