1) Avoid using the length() function. Length returns the longest dimension which could be the number of columns or the num of rows - you'll never know. Use size(points,2) or size(points,1) instead.
2) pre-allocate your loop variables. Instead of G1=[] use G1=nan(size(points)) or use zeros(...). Same with the other G variables.
3) Your condtions do not account for point()=0. That's why you've got a horizontal green line segment at y=0.
4) Use the debugger feature to step through your code to see what it's doing. It's obviously not doing what you intend it to do any by stepping through the code, you can pinpoint where the problem is.
5) (This is the only part of the list that needs a response) What is the intention of the for-loop and all of the conditionals? What's the big-picture of this code? It can very likely be simplified.
