Background
Say I compile the following simple function in MATLAB
function foo(path_to_m_file)
disp([' Running ' path_to_m_file])
run(path_to_m_file);
end
The function foo
just takes a path to an .m file and tries to run it.
However, when I actually try to run foo
after compiling it:
./run_foo.sh $path_to_run_time $path_to_m_file
where path_to_m_file
is a simple .m file with a statement such as:
a = 2;
I get the following error:
Error using ==> run
MATLAB:run:FileNotFound
However, I know that foo
gets the correct path. For example, if I try replacing the line with run
by the following two lines in foo
fID = fopen(conf_file, 'rt');
first_line = textscan(fID, '%s', Inf, 'Delimiter', '\n');
foo
reads the corresponding line of the .m
file. So the .m
file is there, and the MATLAB engine can "see" it. Indeed I can even run eval
on strings read with textscan
.
So my questions are:
Why do I get the error above? Why doesn't
foo
run the.m
file?Update: See @strictlyrude27's answer below for what seems to be an answer to this question.
If the above doesn't work. Is there a way to get a MATLAB-compiled function to run an .m file that may have changed after compiling the original function?
The motivation for my second question:
I would like to have the ability to "update" an .m
file that is part of the project without having to re-compile the full project. Any ideas for this would be greatly appreciated.