Merge multiple functions+scripts in single file
18 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to group together 4 functions and 2 script files in the same file. Let's call the functions A,B,C and D and the scripts f and g. The way I want this "one-file program" to work is the following:
1) Script f calls function A.
2) Function A calls function C.
-----------------------------
3) Script g calls 2 functions: Function A and D.
4) Function A calls function B.
5) Function D calls function B.
What I want is a file which contains and does all of the above. I managed to make a function which contains functions A and D, but I can't add the others since they are called by functions A and D. I've also been doing some research on "classes" which I've never used before and don't know anything about, but from reading I'm not sure classes will do the trick (I tried them without success, but didn't try very hard)
All I want to know is if this doable or is it too complicated? And if it is doable, what should I use ? Is it classes or something else ?
Thanks a lot to anyone who helps, I've really been working very hard on this and can't seem to make the program work.
0 个评论
回答(2 个)
Honglei Chen
2012-2-21
编辑:John Kelly
2015-2-26
You can only declare subfunctions within a function so unless you are willing to rewrite your scripts into functions, you may not be able to achieve what you want.
Some relevant information:
0 个评论
Jean
2012-2-21
2 个评论
Honglei Chen
2012-2-21
I couldn't comment much as I don't see the error. However, using function name in string is always tricky. I would suggest to give function handle a try.
http://www.mathworks.com/help/techdoc/matlab_prog/f2-38133.html
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!