READ THE CODE YOU WROTE.
What is that end doing there?
What happens when MATLAB tries to use this function? What does MATLAB do when it sees the end?
What did it say?
Line: 6 Column: 1 This statement is not inside any function.
So after the end, is the rest of the code you wrote inside the function? NO? What will MATLAB do then? In fact, it gets upset, and it gives up.
What that code is supposed to do there, we don't know. Maybe that end statement is supposed to be there. How can we know? Only you know that.
When MATLAB tells you there is a problem in line 6, you might look at line 5, or line 4. Did you do something strange there?