Matlab programming row echelon form of matrix
<p>Here I wrote a code in matlab to reduce a matrix to row echelon form</p>

<pre><code>function A = myrref(A)

[m,n]=size(A);

for j=1:m

    A(j,:) = A(j,:)/A(j,j);

    for i = 1:n
        if j &lt; i
        A(i,:)= A(i,:)- A(j,:)*A(i,j);
        end
    end
end
</code></pre>

<p>I have a problem though, this code does not seem to work for non square matrices. What am I doing wrong? Thanks.</p>