For example, let's say I have a file named my_file.m, I'd like to do:
file_fullpath = ['path_to_file', filesep, 'my_file.m'];
is_function(file_fullpath)
I'd like a command (which is not is_function) that would determine if file_fullpath is a function or just a script and throw an error if the file does not exist or has some syntax problem that makes it undecidable. I'm guessing there should exist some built-in function to do it since Matlab correctly assigns different icons for functions and scripts in the navigator.
I could write a function to parse the file, looking for the appropriate keywords, but it would probably neither be simple, fast nor necessary.
my_file(...). If it's a function, it should run. If not, it should throw an error.function. This is all you need to look for. Discard lines that start with%, and expectfunction.