How to test if a function handle belongs to a particular package?
Mostrar comentarios más antiguos
I have a method that accepts a function handle and then needs to branch depending on whether that function is part of +package1 or +package2. While I can think of some hacks involving parsing the function name and/or package's help text and/or output of dir, is there a better or simpler way?
thanks, -n
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 29 de Abr. de 2017
As an example, to find out the folder of the bwdist function in the Image Processing Toolbox:
functionInfo = which('bwdist')
[folder, baseFileNameNoExt, ext] = fileparts(functionInfo)
Here is the file/folder info that is returned:
functionInfo =
'C:\Program Files\MATLAB\R2017a\toolbox\images\images\bwdist.m'
folder =
'C:\Program Files\MATLAB\R2017a\toolbox\images\images'
baseFileNameNoExt =
'bwdist'
ext =
'.m'
Adapt as needed for your function names.
5 comentarios
Naor Movshovitz
el 29 de Abr. de 2017
Naor Movshovitz
el 29 de Abr. de 2017
I don't see how which is any use to the "question as posed". Since a function handle is just a variable like any other, which will just reply 'variable'.
>> fn = @(x) x+1;
>> functioninfo = which('fn');
functioninfo =
variable
Image Analyst
el 29 de Abr. de 2017
I got the impression that he "needs to branch depending on whether that function is part of +package1 or +package2" so I figured that if he could figure out the folder where that function lives, then he'd know which package it belonged to. That was my thinking.
Naor Movshovitz
el 30 de Abr. de 2017
Categorías
Más información sobre Data Type Identification en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!