Why I need this. I get files from another guy that is
written as just code and I like to be able to run the file
in my code without changing anything in his file since he is
updating it all the time to a CVS system...so I can't change
the file everytime he puts up a new file.
Thanks
HS
~S
"Henrik " <henrik...@lanl.gov> wrote in message
<fcbnen$rdu$1...@fred.mathworks.com>...
No, not directly.
If you're trying to call the main function of another file inside your first
file, just call it like any other MATLAB function.
If you're trying to call a subfunction in the second file from within your
first file, you can have the main function in the second file be a
"switchyard" that accepts the name of the subfunction to call:
% begin switchyard.m
function y = switchyard(fcn, x)
% Call as:
% y = switchyard('mycos', 1:10);
% or
% y = switchyard('mysin', pi);
y = feval(fcn, x);
function y = mycos(x)
y = cos(x);
function y= mysin(x)
y = sin(x);
% end switchyard.m
or you can have the main function return a handle to the subfunction and
call them that way:
% begin createhandles.m
function s = createhandles
% Call as:
% s = createhandles
% y1 = s.mycos(1:10);
% y2 = s.mysin(pi);
s.mycos = @mycos;
s.mysin = @mysin;
function y = mycos(x)
y = cos(x);
function y= mysin(x)
y = sin(x);
% end createhandles.m
If the other file is a script, just run it by typing the name of the script.
--
Steve Lord
sl...@mathworks.com
[...]
%
% Here we insert the following code simulating php include behavior:
% read lines in file 'file1' and execute them as matlab commands.
% No empty lines allowed in file1.
%
fid=fopen('file1','r');
ligne=' '; % init of line
while(ischar(ligne)); % if ligne is not void do
clear ligne % clear previous value of ligne
comd=fgetl(fid); % read a line from file1
if (~ischar(comd)); % Stops if line is void
break
end
eval(comd); % execution of ligne as it was a matlab command
end
fclose(fid);
[...]
main code continues here
"Henrik " <henrik...@lanl.gov> wrote in message <fcbnen$rdu$1...@fred.mathworks.com>...
return function handles for your 2 functions when you call file1. Pass
these to file2 for use.
--
Loren
http://blogs.mathworks.com/loren