user673218
user673218

Reputation: 411

Matlab header files

I have some part of code that is repeated in a number of matlab funcions (.m files). I want to put the code into functions that can be defined in a single file (say CommandHelper.m) and use these functions in my original .m files. (just as defined in header files). Is this possible?

Upvotes: 1

Views: 1930

Answers (1)

zellus
zellus

Reputation: 9582

MATLAB comes with a full featured object model as documented in Object-Oriented Programming. You may provide your helper functions as static methods.

classdef CommandHelper   
    methods (Static)
        function text = firstCommand()
           text = 'firstCommand'; 
        end

        function text = secondCommand()
           text = 'secondCommand'; 
        end
    end       
end

Helper functions may be called from the command line or any other function, script with the following syntax.

>> CommandHelper.firstCommand

ans = firstCommand

>> CommandHelper.secondCommand

ans = secondCommand

Upvotes: 1

Related Questions