Nested Function In For Loop Matlab