MATLAB: How to put 2 functios together in just one function

2functionsinone putfunctionstogheter

Hi there! I have created 2 functions :
function [tk]= time(t,toe)
ti=t-toe;
if ti>302400;
tk= ti-604800;
elseif tk<-302400;
tk = ti+604800;
end
end
and the second function :
function [mk] = meanan(mo,a,u,n,tk)
mk = mo +((sqrt(u)/sqrt(a^3))+n)*tk
end
Now my question is : Can I put this 2 functions in just one function in MATLAB? I've been looking on internet but what I found is NO, it is not possible. Is it right? I cannot put 2,3 or maybe more functions in just one? Thank you!

Best Answer

function mk = meanantime(mo, a, u, n, t, toe)
ti=t-toe;
if ti>302400;
tk= ti-604800;
elseif tk<-302400;
tk = ti+604800;
end
mk = mo +((sqrt(u)/sqrt(a^3))+n)*tk;
But what I suspect you are asking is whether you can put multiple functions into the same .m file and still be able to call each one from outside of the .m file.
The answer to that is "Not easily". Someone did, however, point out the other day that it is possible to create static class methods that can be invoked by name from outside the .m file. This would require changing the combined .m file into a classdef with appropriate structuring.