The typical way to do this is to create a MATLAB .m file to implement your function. Open the MATLAB Editor with a blank file (File>New>Script), and in the blank file, type the following:
function y = myfun(x)
y = 2*x+1;
Then save the file as myfun.m.
At the MATLAB command line, now type
>> myfun(2)
ans =
5
That would be the typical thing to do if you need to reuse the function a few times. If you need a more throwaway function, you can at the command line just type
The typical way to do this is to create a MATLAB .m file to implement your function. Open the MATLAB Editor with a blank file (File>New>Script), and in the blank file, type the following:
Then save the file as myfun.m.
At the MATLAB command line, now type
That would be the typical thing to do if you need to reuse the function a few times. If you need a more throwaway function, you can at the command line just type