From: forkandwait w on
Hi all,

Is there a way to generate a list of all functions defined recursively under a path, such that you can loop over that list? I think this is two questions -- how to loop over cell arrays of strings, and how to get a list of all defined funcs.

Thx!
From: Matt J on
"forkandwait w" <forkandwait(a)gmail.com> wrote in message <hoisl9$phm$1(a)fred.mathworks.com>...
> Hi all,
>
> Is there a way to generate a list of all functions defined recursively under a path, such that you can loop over that list? I think this is two questions -- how to loop over cell arrays of strings, and how to get a list of all defined funcs.
======


The function down at the bottom of this post will create a cell array containing all directories in a path. To generate a path recursively, use genpath, e.g.

C=path2cell(genpath(pwd)) %All path directories

Now, to get the .m files in each directory, you can loop over the cells in C and call the what() function on each,

FuncList={};
for ii=1:length(C)

W=what(C{ii});

FuncList=[FuncList{:} , W.m];

end

Of course, as usual, it's better to pre-allocate your cell arrays, rather than concatenate on the fly in a for-loop.



function C=path2cell(pathstr)
%PATH2CELL - converts a path string (directories separated by pathsep) to a
%cell containing each directory name
%
% C=path2cell(pathstr)
%
%E.g.
%
% C=strvcat(path2cell(path)), %alternative way of pretty-printing the path



p=pathstr(:).';

seps=find([pathsep p pathsep]==pathsep);

blklens=diff(seps)-1;

p(pathstr==pathsep)='';

blklens=nonzeros(blklens);

C=mat2cell(p,1,blklens);
C=C(:);
From: AJ on
"forkandwait w" <forkandwait(a)gmail.com> wrote in message <hoisl9$phm$1(a)fred.mathworks.com>...
> Hi all,
>
> Is there a way to generate a list of all functions defined recursively under a path, such that you can loop over that list? I think this is two questions -- how to loop over cell arrays of strings, and how to get a list of all defined funcs.
>
> Thx!

I recommend recursive calls to "depfun".
AJ
From: us on
"forkandwait w" <forkandwait(a)gmail.com> wrote in message <hoisl9$phm$1(a)fred.mathworks.com>...
> Hi all,
>
> Is there a way to generate a list of all functions defined recursively under a path, such that you can loop over that list? I think this is two questions -- how to loop over cell arrays of strings, and how to get a list of all defined funcs.
>
> Thx!

just a question: are you

- simply looking for all M-files within a folder and its subfolder(s)...
- looking for dependecies of a (main-) function...

us
From: Steven Lord on

"forkandwait w" <forkandwait(a)gmail.com> wrote in message
news:hoisl9$phm$1(a)fred.mathworks.com...
> Hi all,
>
> Is there a way to generate a list of all functions defined recursively
> under a path, such that you can loop over that list? I think this is two
> questions -- how to loop over cell arrays of strings, and how to get a
> list of all defined funcs.

I can think of a few scenarios where you could want to do that, but in many
of those scenarios I can also think of ways to do the task in that scenario
more efficiently. What are you trying to do with this list?

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


 |  Next  |  Last
Pages: 1 2 3
Prev: mean block in simulink
Next: Newbie Newey-West