Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: "include" a .m file into another .m file
Date: Fri, 13 Mar 2009 12:53:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 51
Message-ID: <gpdkvd$p4t$1@fred.mathworks.com>
References: <fcbnen$rdu$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1236948781 25757 172.30.248.35 (13 Mar 2009 12:53:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 13 Mar 2009 12:53:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1754289
Xref: news.mathworks.com comp.soft-sys.matlab:524576


%  main script body

[...] 
%
% 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 " <henrikNOSPAM@lanl.gov> wrote in message <fcbnen$rdu$1@fred.mathworks.com>...
> Hey
> I was wondering if matlab supports adding all text from a
> .m-file (not a function file just code that runs buy it
> self) to another .m file that I'm running.
> Like php scripts that you can import anywhere in your php
> file buy just typing include(FILENAME). 
> So I have a file test.m that is a function. I call it
> test(obj) and it starts running. It comes to an "include"
> statement and it just keeps running through the included
> file with all it's calculations and stuff and when it comes
> to the end of the file it just continues in the test file
> with the line after the "include" statement.
> 
> 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 
>