# Thread: Mat lab - Referencing M-file in another M-file

1. ## 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

2. Originally Posted by rem88
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

3. 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

4. Originally Posted by rem88
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

5. 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

6. 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