Let $M \in \mathbb{R}^{m \times n}$ be a matrix of rank $r$, and $w^1, w^2 \in \mathbb{R}^{m \times n}$ be such that $\sum_{i,j} w^1_{i,j}=\sum_{i,j} w^2_{i,j} =1$. Let $\varepsilon >0$. I want to prove that $$\inf_{M'} \sum_{i,j} w^1_{i,j}\left( M_{i,j}-M'_{i,j}\right)^2 \text { such that } \sum_{i,j} w^2_{i,j}\left(M_{i,j}-M'_{i,j}\right)>\varepsilon \text { and } \operatorname{rank}(M')=r $$ is equal to $$\inf_{M'} \sum_{i,j} w^1_{i,j}\left( M_{i,j}-M'_{i,j}\right)^2 \text { such that } \sum_{i,j} w^2_{i,j}\left(M_{i,j}-M'_{i,j}\right)>\varepsilon \text { and } \operatorname{rank}(M') \leq r $$
Clearly the first infimum is larger than the second one. I'd like to prove that they are actually equal. This seems true to me because I think that one can perturb a matrix $M'$ of rank strictly smaller than $r$ to make it rank $r$ without changing its entries very much. Is this intuition correct ? How could I formalize it ?
This seems to be a purely topological problem. The rank $r$ matrices are dense in the rank $\leq r$ matrices, so treating those functions now as arbitrary continuous functions and your sets of matrices as arbitrary topological spaces, one dense in the other, may be easier.
To see that rank $r$ matrices are dense:
First of all invertible matrices are dense in $M_n(\mathbb R)$ because if not, then the determinant vanishes on an open set. This is a polynomial (in $n^2$ variables), so if it vanishes on an open set, then it vanishes everywhere, which is a contradiction.
By Gauss elimination, rank $r$ matrices of size $m \times n$ are the image of the map $$\begin{align}\operatorname{GL}_m(\mathbb R) \times \operatorname{GL}_n(\mathbb R) &\to \mathbb R^{m \times n} \\ (A, B) \mapsto A D B \,,\end{align}$$ where $D$ is an $m \times n$ matrix with $r$ ones on the diagonal.
The set of all rank $\leq r$ matrices is the image of the same map but where the LHS is extended to all of $\mathbb R^{m \times m} \times \mathbb R^{n \times n}$.
Then use that a surjective continuous map sends dense subsets to dense subsets.