Print subfunction names to text file

조회 수: 8 (최근 30일)
Andrew Smelser
Andrew Smelser 2019년 1월 16일
댓글: Andrew Smelser 2019년 2월 7일
I need to print the function names of subfunctions inside a classdef to a .txt file. I'd like to do it quickly without having to go in and copy paste each function name everytime i revise this code. This will be used to generate a change log for a README.
here's my basic setup:
classdef master
methods(Static)
function f1()
%stuff
end
function f2()
%stuff
end
function f3()
%stuff
end
end
end
And I want to run a function in matlab that will output something like:
File names in master.m:
master.f1()
master.f2()
master.f3()
into a text file. I know how to save as a text file, and other fprintf formatting is easy. I just don't know how to go into the classdef and grab those function names. Is there an easy way to do this?
I'm using MATLAB R2018a

채택된 답변

Adam
Adam 2019년 1월 16일
편집: Adam 2019년 1월 16일
m = methods( 'master' )
will give you the information you need. Then you can tag the class name on the front or whatever else you want for formatting. Note this will only give the public functions though. If you need to delve into more detail then
doc metaclass
can do this, e.g.
mc = metaclass( 'master' );
methodList = mc.MethodList;
This will give you all functions, including private ones, with lots of detail too. Again for just the names you can then do:
methodNames = { methodList.Name };
Feel free to nosey around on the command line at the other details you get in mc and in methodList also if they are of use to you for filtering the method list in some way, such as by Static functions, Abstract functions, etc.
  댓글 수: 1
Andrew Smelser
Andrew Smelser 2019년 2월 7일
Thanks! Works well enough for my purposes :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Adding custom doc에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by