“include” a .m file into another .m file

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.

 

2 Responses

  1. hello.

    I used improfile.I need a syntax that shows x and y for the min and max peaks.
    how can I found x and y of the peaks. in the rgb plot that improfile shows?
    many thanks,

  2. Check this: “peakdet: Peak detection using MATLAB” at http://billauer.co.il/peakdet.html. Maybe this is what you’re looking for…

    Alen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: