MATLAB: Trouble on finding line segment shows error

linesegment functionmisplaced

the output result of my coding shows function definition misplaced. is there any solution for this little mistake ?
>> FindSegment(1, 1)
Error: File: FindSegment.m Line: 87 Column: 4
Function definition is misplaced or improperly
nested.
i attached the source code here

Best Answer

Why are you nesting the second and third functions inside the first one? Don't. There is no need to. Have them be three separate, non-nested functions. And get rid of the extra end at the last line of the file - move it to just before you define the second function to finish off the declaration of the first function.