function [out1, out2] = m_file (in1, in2) %M_FILE is a sample program written in MATLAB % % [out1, out2] = m_file(in1, in2) % % Everything written in the comment block directly after the initial % function declaration will be printed when 'help m_file' is displayed. % If you will ever use your function again, take this chance to explain to % your future self and others how it will be used! % % See also TIM_DEMO, MATLAB_TYPES % This comment is considered to be in a separate block, so it's not printed % with the help message % To use this file as a script, simply comment out the top line; then all % variables created in the file will be available in the workspace where % it's run. Otherwise, only the first output argument and %% SECTION 1 % Using two comments at the beginning of a line will cause the MATLAB % editor to create a new section of highlighted code. This helps organize % the code you write if you use the MATLAB environment. %%% Any number of comment symbols other than two is normal % %% % Try to avoid 'magic numbers'; if your code uses a number more than once, % assign it its own variable so that it can be changed in only one place. % That way other people can more easily use and edit your code later. to_add = 3; out1 = []; for i = 1:in1 % Growing an array horizontally out1 = [out1, i + to_add]; end %% SECTION 2 % The MATLAB editor has a vertical line at 76 characters -- use it! People have a difficult time reading % more than about 3 alphabets across (78 characters) because they lose the next line, so at least keep % your code lines at a maximum of 80 characters long, if not 76. out2 = ones(1, in1); for i = 1:in1 out2(i) = i + to_add; end % MATLAB allows for all kinds of spacing; the only rule is that yours % should be both readable and consistent. These are all acceptable: % % my_function(argument,argument+1) % my_function(argument, argument+1) % my_function( argument, (argument + 1) ) % my_function (argument, argument + 1) % and many more...