Imagine I implement a function that calls a subfunction. Keeping the subfunction in the .m
file keeps things more compact, so I'd like to do that. However, for debugging purposes, I need to call that subfunction. I try to do that, and I get File not found
, or a similar error. Is there a way to call a subfunction that is in the same .m
file as another function from outside that function?
Asked
Active
Viewed 111 times
1

Luis Mendo
- 110,752
- 13
- 76
- 147

MickG
- 3,216
- 2
- 14
- 22
-
2As far as I know you can't, as the function is not defined within the scope of where you're calling it. Check out: http://www.mathworks.com/matlabcentral/answers/92762-why-am-i-unable-to-run-a-subfunction-from-outside-its-main-function-or-as-a-callback-function for more details. It'll give you some hints on how to achieve this if you must... but the easiest way is to create a new `.m` file with this function defined in it. – rayryeng Sep 15 '14 at 22:24
-
1For a similar issue I switched to private functions in a private directory. The can be accessed using the full path: http://stackoverflow.com/questions/24612002/how-to-isolate-unittests-in-matlab/24616475 – Daniel Sep 15 '14 at 22:48
1 Answers
0
There's no way around this. If you want to call a function from the command prompt or from multiple .m files you must put it into a separate .m file.
The only possible alternative is to have a class with multiple public methods.

Dima
- 38,860
- 14
- 75
- 115