Results 1 to 6 of 6

Math Help - Mat lab - Referencing M-file in another M-file

  1. #1
    Junior Member
    Joined
    Apr 2009
    Posts
    44

    Mat lab - Referencing M-file in another M-file

    Hi,

    I was wondering if there is away to reference a m file to be used in a nother m file.

    E.g. i have a m file:

    function
    [Fexp] = exponential_feed

    t = [0:1:15];
    for i=1:length(t);
    Fexp = 0.8*exp(0.03*t);
    end
    end

    I also have another m-file where in the worksapce i ahve to input fermsettings.flow = Fexp.

    I was wondering if i can put into the 1st m file, so when i run it i dont have to input it into the workspace.

    Rem
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by rem88 View Post
    Hi,

    I was wondering if there is away to reference a m file to be used in a nother m file.

    E.g. i have a m file:

    function
    [Fexp] = exponential_feed

    t = [0:1:15];
    for i=1:length(t);
    Fexp = 0.8*exp(0.03*t);
    end
    end

    I also have another m-file where in the worksapce i ahve to input fermsettings.flow = Fexp.

    I was wondering if i can put into the 1st m file, so when i run it i dont have to input it into the workspace.

    Rem
    I'm not sure what you are really asking, but any .m file on the search path can be called by any .m file or from the console.

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Junior Member
    Joined
    Apr 2009
    Posts
    44
    Thanks for your response, what i meant was use a m file in anthoer m file, but i worked it out.

    There was another porblem i was having though. I have the following function:

    function [feed] = feed;
    t = [0:1:100];
    for i=1:50;
    feed = 0.8*exp(0.3*t);
    end

    This works fine, but after the 100 time units i want a different fucntion to run. I tried this, but only the second function runs:

    function [feed] = feed;
    t = [0:1:100];
    for i=1:50;
    feed = 0.8*exp(0.3*t);
    end

    i=50:100;
    feed = 0.8*t;


    end

    Rem

    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by rem88 View Post
    Thanks for your response, what i meant was use a m file in anthoer m file, but i worked it out.

    There was another porblem i was having though. I have the following function:

    function [feed] = feed;
    t = [0:1:100];
    for i=1:50;
    feed = 0.8*exp(0.3*t);
    end

    This works fine, but after the 100 time units i want a different fucntion to run. I tried this, but only the second function runs:

    function [feed] = feed;
    t = [0:1:100];
    for i=1:50;
    feed = 0.8*exp(0.3*t);
    end

    i=50:100;
    feed = 0.8*t;


    end

    Rem

    Both of those almose certainly don't do what you want, but it is not obviouse what you do want them to do

    Code:
    function [feed] = feed;
    t = [0:1:100];
    
    feed = 0.8.*exp(0.3.*t(0:50));
    
    feed = [feed,0.8.*t(51:100)];
    might do something interesting

    CB
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Junior Member
    Joined
    Apr 2009
    Posts
    44
    Hi,

    I tried that and i got this error

    ??? Subscript indices must either be real positive integers or logicals.
    Error in ==> feed2 at 4
    feed2 = 0.8.*exp(0.3.*t(0:50));

    ---------------------------------------------------------------------

    This first function works from 0 to 50

    function [feed] = feed;
    t = [0:1:50];
    for
    i=1:length(i);
    feed = 0.8*exp(0.3*t);
    end


    But what i want, is when this is done after 50 i want a second function to start running which is

    feed=0.8*t

    But i am not sure how to do this.

    Rem
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    is this what you are asking for?
    Code:
    function f = feed
    t = 1:75;
    f(t <= 50) =  0.8*exp(0.3*t(t<=50));
    f(t>50) = 0.8*t(t > 50);
    Elbarto
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. m file failure?
    Posted in the Math Software Forum
    Replies: 18
    Last Post: April 26th 2010, 04:15 AM
  2. Differentiation m-file help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: April 17th 2010, 09:20 PM
  3. need a m-file
    Posted in the Math Software Forum
    Replies: 3
    Last Post: March 7th 2010, 12:31 AM
  4. Matlab M file
    Posted in the Math Software Forum
    Replies: 4
    Last Post: April 18th 2009, 03:34 AM

Search Tags


/mathhelpforum @mathhelpforum