The full question is:
Let $M \in \mathbb{R}^{n\times m}$ and $r=\operatorname{rank}(M)$. Show there exists $A\in\mathbb{R}^{n\times r}$ and $B\in\mathbb{R}^{r\times m}$ such that $M=AB$.
So the way I tried it was that there are $r$ number of basis vectors $v_1,\dots, v_r$. And $M$ can be expressed as $$ \begin{bmatrix} | & | & & |\\ m_{1,1}v_1+\cdots+m_{n,1}v_r & m_{1,2}v_1+\cdots+m_{n,2}v_r & \dots & m_{1,m}v_1+\cdots+m_{n,m}v_r \\ | & | & & | \end{bmatrix} $$ So all the columns can be expressed as the linear combinations of linearly independent columns in $M$, but I'm not sure where to go from here to prove that $M=AB$.
Could anyone help please?
First all there exist invertible matrices $P_{n\times n}, Q_{m\times m}$ such that $$ PMQ =\left(\begin{matrix}I_{r\times r}&N_{(n-r)\times (m-r)}\\0_{(n-r)\times r}&0_{(n-r)\times(m-r)} \end{matrix}\right). $$ Then $$ M=P^{-1}\left(\begin{matrix}I&N\\0&0 \end{matrix}\right)Q^{-1}=P^{-1}\binom{I}{0}(I, N)Q^{-1}. $$ Let $$ A=P^{-1}\binom{I}{0}, B=(I, N)Q^{-1} $$ and then $$ M=AB. $$ It is easy to check that $\text{rank}{A}=\text{rank}{B}=r$.