writing more than 1 function in a file
조회 수: 3 (최근 30일)
이전 댓글 표시
i wrote each function in each file and now there are too many files in a program. i tried to write several functions in a file but was unable to retrieve and use them. how can i write many functions and use them? thank you.
댓글 수: 0
채택된 답변
Walter Roberson
2012년 11월 8일
You can put more than one function in a file, but the additional functions will only be directly visible to the first function in that file. In order for any outside file to be able to invoke the additional functions, the outside file would need to have access to a function handle for the routine.
One way that you can arrange this is something like,
function funstruct = calculus_library
funstruct.differentiate_polynomial = @diffpoly;
funstruct.integrate_polynomial = @intpoly;
funstruct.differentiate_trig = @difftrig;
end
function r = diffpoly(....)
[...]
function r = difftrig(....)
[...]
That is, make the main routine for the file one that you can call on to retrieve the function handle you are interested in.
댓글 수: 1
Jan
2012년 11월 8일
This method is explained in the Getting Started chapters of the documentation. It is strongly recommended to read them, because Matlab is a very powerful language.
추가 답변 (1개)
Harshit
2012년 11월 8일
편집: Jan
2012년 11월 8일
Use local functions See the link http://www.mathworks.in/help/matlab/matlab_prog/local-functions.html?s_tid=doc_12b
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!