The above is Matlab code
When i insert the max word at line A i get it printed all the time the loop is iterated, even though it's outside the for loop.Code:function max() A = [ 5 4 7 2 6 3 1 ]; max=0; for j = 1:7, if( A(j) > max ) max = A(j); end %first end % line A end %second end max
Why is that?
A single function in an .m file does not require and end (and as far as I recall a function definition in a script file is terminated by the eof marker or the next function statement - the same goes for functions and sub-functions in the same file)
Good practice would say put the end statement in to terminate the function, Matlab will catch up eventually and insist on it.