There are a number of issues with this piece of code.
1) You should not have a clc inside a function. It is bad practice since the user may not want to clear the command window.
2) You have x and q as arguments already so you do not need the input. My advice would be to remove the inputs and either define x and q outside the function or assign them directly in the function call (in in the command window), like xSqrt = my_sqrt(3,0.01).
3) result is not defined. Also, you only need the current x and the previous, my advice would then be to define a new variable xNext and update it. Then either return xNext, update x and return x or define result = x (or xNext depending on when it is updated).
This should work fine:
function [result,n] = my_sqrt(x2,q)
x = 3;
n = 1;
quitLoop = false;
xNext = 0.5*(x+x2/x);
quitLoop = true;
n = n+1;
x = xNext;
result = xNext;
where x2 is defined as the number that you want to calculate the root of. The algorithm uses newton-raphson and have a fast convergence.