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?
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
精彩评论