<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156103</link>
    <title>MATLAB Central Newsreader - &quot;include&quot; a .m file into another .m file</title>
    <description>Feed for thread: &quot;include&quot; a .m file into another .m file</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 13 Sep 2007 16:11:03 -0400</pubDate>
      <title>&quot;include&quot; a .m file into another .m file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156103#392159</link>
      <author>Henrik </author>
      <description>Hey&lt;br&gt;
I was wondering if matlab supports adding all text from a&lt;br&gt;
.m-file (not a function file just code that runs buy it&lt;br&gt;
self) to another .m file that I'm running.&lt;br&gt;
Like php scripts that you can import anywhere in your php&lt;br&gt;
file buy just typing include(FILENAME). &lt;br&gt;
So I have a file test.m that is a function. I call it&lt;br&gt;
test(obj) and it starts running. It comes to an &quot;include&quot;&lt;br&gt;
statement and it just keeps running through the included&lt;br&gt;
file with all it's calculations and stuff and when it comes&lt;br&gt;
to the end of the file it just continues in the test file&lt;br&gt;
with the line after the &quot;include&quot; statement.&lt;br&gt;
&lt;br&gt;
Why I need this. I get files from another guy that is&lt;br&gt;
written as just code and I like to be able to run the file&lt;br&gt;
in my code without changing anything in his file since he is&lt;br&gt;
updating it all the time to a CVS system...so I can't change&lt;br&gt;
the file everytime he puts up a new file. &lt;br&gt;
&lt;br&gt;
Thanks &lt;br&gt;
HS </description>
    </item>
    <item>
      <pubDate>Thu, 13 Sep 2007 16:20:00 -0400</pubDate>
      <title>Re:</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156103#392161</link>
      <author>John </author>
      <description>You mean you are running matlab scripts. All you have to do&lt;br&gt;
is call the script wherever you want to 'include' it. i.e in&lt;br&gt;
in test.m if you want to run the other script , say file1.m&lt;br&gt;
at say line 20 just call it by typing file1 ; &lt;br&gt;
Ofcourse, file1 must be in a directory thats in your path&lt;br&gt;
variable, otherwise you will have to specify the full&lt;br&gt;
pathname instead of just file1;&lt;br&gt;
&lt;br&gt;
~S&lt;br&gt;
&lt;br&gt;
&quot;Henrik &quot; &amp;lt;henrikNOSPAM@lanl.gov&amp;gt; wrote in message&lt;br&gt;
&amp;lt;fcbnen$rdu$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hey&lt;br&gt;
&amp;gt; I was wondering if matlab supports adding all text from a&lt;br&gt;
&amp;gt; .m-file (not a function file just code that runs buy it&lt;br&gt;
&amp;gt; self) to another .m file that I'm running.&lt;br&gt;
&amp;gt; Like php scripts that you can import anywhere in your php&lt;br&gt;
&amp;gt; file buy just typing include(FILENAME). &lt;br&gt;
&amp;gt; So I have a file test.m that is a function. I call it&lt;br&gt;
&amp;gt; test(obj) and it starts running. It comes to an &quot;include&quot;&lt;br&gt;
&amp;gt; statement and it just keeps running through the included&lt;br&gt;
&amp;gt; file with all it's calculations and stuff and when it comes&lt;br&gt;
&amp;gt; to the end of the file it just continues in the test file&lt;br&gt;
&amp;gt; with the line after the &quot;include&quot; statement.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Why I need this. I get files from another guy that is&lt;br&gt;
&amp;gt; written as just code and I like to be able to run the file&lt;br&gt;
&amp;gt; in my code without changing anything in his file since he is&lt;br&gt;
&amp;gt; updating it all the time to a CVS system...so I can't change&lt;br&gt;
&amp;gt; the file everytime he puts up a new file. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks &lt;br&gt;
&amp;gt; HS &lt;br&gt;
&amp;gt; </description>
    </item>
    <item>
      <pubDate>Sun, 16 Sep 2007 04:51:42 -0400</pubDate>
      <title>Re: &quot;include&quot; a .m file into another .m file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156103#392495</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Henrik &quot; &amp;lt;henrikNOSPAM@lanl.gov&amp;gt; wrote in message &lt;br&gt;
news:fcbnen$rdu$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Hey&lt;br&gt;
&amp;gt; I was wondering if matlab supports adding all text from a&lt;br&gt;
&amp;gt; .m-file (not a function file just code that runs buy it&lt;br&gt;
&amp;gt; self) to another .m file that I'm running.&lt;br&gt;
&amp;gt; Like php scripts that you can import anywhere in your php&lt;br&gt;
&amp;gt; file buy just typing include(FILENAME).&lt;br&gt;
&lt;br&gt;
No, not directly.&lt;br&gt;
&lt;br&gt;
If you're trying to call the main function of another file inside your first &lt;br&gt;
file, just call it like any other MATLAB function.&lt;br&gt;
If you're trying to call a subfunction in the second file from within your &lt;br&gt;
first file, you can have the main function in the second file be a &lt;br&gt;
&quot;switchyard&quot; that accepts the name of the subfunction to call:&lt;br&gt;
&lt;br&gt;
% begin switchyard.m&lt;br&gt;
function y = switchyard(fcn, x)&lt;br&gt;
% Call as:&lt;br&gt;
%   y = switchyard('mycos', 1:10);&lt;br&gt;
% or&lt;br&gt;
%   y = switchyard('mysin', pi);&lt;br&gt;
&lt;br&gt;
y = feval(fcn, x);&lt;br&gt;
&lt;br&gt;
function y = mycos(x)&lt;br&gt;
y = cos(x);&lt;br&gt;
function y= mysin(x)&lt;br&gt;
y = sin(x);&lt;br&gt;
% end switchyard.m&lt;br&gt;
&lt;br&gt;
or you can have the main function return a handle to the subfunction and &lt;br&gt;
call them that way:&lt;br&gt;
&lt;br&gt;
% begin createhandles.m&lt;br&gt;
function s = createhandles&lt;br&gt;
% Call as:&lt;br&gt;
%   s = createhandles&lt;br&gt;
%   y1 = s.mycos(1:10);&lt;br&gt;
%   y2 = s.mysin(pi);&lt;br&gt;
&lt;br&gt;
s.mycos = @mycos;&lt;br&gt;
s.mysin = @mysin;&lt;br&gt;
&lt;br&gt;
function y = mycos(x)&lt;br&gt;
y = cos(x);&lt;br&gt;
function y= mysin(x)&lt;br&gt;
y = sin(x);&lt;br&gt;
% end createhandles.m&lt;br&gt;
&lt;br&gt;
If the other file is a script, just run it by typing the name of the script.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com </description>
    </item>
    <item>
      <pubDate>Fri, 13 Mar 2009 12:53:01 -0400</pubDate>
      <title>Re: &quot;include&quot; a .m file into another .m file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156103#634580</link>
      <author>eduardo damasio da costa</author>
      <description>%  main script body&lt;br&gt;
&lt;br&gt;
[...] &lt;br&gt;
%&lt;br&gt;
% Here we insert the following code simulating php include behavior:&lt;br&gt;
% read lines in file 'file1' and execute them as matlab commands.&lt;br&gt;
% No empty lines allowed in file1.&lt;br&gt;
%&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;fid=fopen('file1','r');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;ligne='  ';                         % init of line&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;while(ischar(ligne));               % if ligne is not void do&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;clear ligne                 % clear previous value of ligne   &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;comd=fgetl(fid);            % read a line from file1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (~ischar(comd));         % Stops if line is void&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;eval(comd);                 % execution of ligne as it was a matlab command&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;fclose(fid);&lt;br&gt;
&lt;br&gt;
[...]&lt;br&gt;
main code continues here&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;Henrik &quot; &amp;lt;henrikNOSPAM@lanl.gov&amp;gt; wrote in message &amp;lt;fcbnen$rdu$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hey&lt;br&gt;
&amp;gt; I was wondering if matlab supports adding all text from a&lt;br&gt;
&amp;gt; .m-file (not a function file just code that runs buy it&lt;br&gt;
&amp;gt; self) to another .m file that I'm running.&lt;br&gt;
&amp;gt; Like php scripts that you can import anywhere in your php&lt;br&gt;
&amp;gt; file buy just typing include(FILENAME). &lt;br&gt;
&amp;gt; So I have a file test.m that is a function. I call it&lt;br&gt;
&amp;gt; test(obj) and it starts running. It comes to an &quot;include&quot;&lt;br&gt;
&amp;gt; statement and it just keeps running through the included&lt;br&gt;
&amp;gt; file with all it's calculations and stuff and when it comes&lt;br&gt;
&amp;gt; to the end of the file it just continues in the test file&lt;br&gt;
&amp;gt; with the line after the &quot;include&quot; statement.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Why I need this. I get files from another guy that is&lt;br&gt;
&amp;gt; written as just code and I like to be able to run the file&lt;br&gt;
&amp;gt; in my code without changing anything in his file since he is&lt;br&gt;
&amp;gt; updating it all the time to a CVS system...so I can't change&lt;br&gt;
&amp;gt; the file everytime he puts up a new file. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks &lt;br&gt;
&amp;gt; HS &lt;br&gt;
&amp;gt; </description>
    </item>
    <item>
      <pubDate>Mon, 11 Jan 2010 15:08:02 -0500</pubDate>
      <title>Re: &quot;include&quot; a .m file into another .m file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156103#707633</link>
      <author>dfgdfg </author>
      <description>i have a file1.m where two functions defined.f1 and f2;&lt;br&gt;
I wabt to use these functions in file file2.m.How can i do this?</description>
    </item>
    <item>
      <pubDate>Mon, 11 Jan 2010 20:28:02 -0500</pubDate>
      <title>Re: &quot;include&quot; a .m file into another .m file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156103#707712</link>
      <author>Loren Shure</author>
      <description>In article &amp;lt;hifesi$9kq$1@fred.mathworks.com&amp;gt;, AP@mathworks.com says...&lt;br&gt;
&amp;gt; i have a file1.m where two functions defined.f1 and f2;&lt;br&gt;
&amp;gt; I wabt to use these functions in file file2.m.How can i do this?&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
return function handles for your 2 functions when you call file1.  Pass &lt;br&gt;
these to file2 for use.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Loren&lt;br&gt;
&lt;a href=&quot;http://blogs.mathworks.com/loren&quot;&gt;http://blogs.mathworks.com/loren&lt;/a&gt;</description>
    </item>
  </channel>
</rss>

