Thursday 4 December 2014

How to have all the functions in a single file, instead of having individual .m file for each function, in Matlab?

1. It is easy. It can be done by using functions-even the top level script should also be written as a function. An example is given below:

All these functions are present in Top.m

function Top
a = GetValue(1);
b = GetValue(2);
s = Sum2Num(a,b)
end

function val = GetValue(n)
val = n;
end


function s = Sum2Num(a,b)
s = a + b;
end


No comments:

Post a Comment