Ted Flethuseo
Ted Flethuseo

Reputation: 395

how to add multiple functions in matlab

I want to add several functions from a single .m file. Is this possible without actually having to create an individual m file for each function?

Upvotes: 5

Views: 12406

Answers (1)

John Alexiou
John Alexiou

Reputation: 29274

For later versions of Matlab that support the classdef keyword, I recommend adding the functions as static methods to a class and then calling them from an instance of that class. It can all be done with one .m file:

classdef roof
  methods (Static)
    function res = f1(...)
        ...
    end
    function res = f2(...)
        ...
    end
  end
end

and you call them by

roof.f1();
roof.f2();

Upvotes: 10

Related Questions