If two complex numbers $a, b$ are such that $|a| = |b|$ then there is a unitary complex number $e^{i\theta}$ such that $$a = b e^{i\theta}$$
Does this hold also for matrices? My best guess is that we need to check the determinants: if $|\det A| = |\det B|$ there is a unitary matrix $U$ such that $A = BU$.
Is that true? I think it is true if they also share a basis of left singular vectors by simply looking at a SVD of the two matrices, but I wanted to better understand the statement above.
For two matrices $A,B \in \Bbb C^{n \times n}$, there exists a unitary matrix $U$ such that $A = BU$ if and only if $AA^* = BB^*$, where $A^*$ denotes the conjugate-transpose of $A$.
In terms of singular vectors, $AA^* = BB^*$ will hold if and only if $A,B$ have a common basis of left singular vectors and the same (corresponding) singular values.
Here is a quick proof of this using the SVD. Write $A = V_A\Sigma_AW_A^*$ and $B = V_B \Sigma_B W_B^*$, where the matrices $V_A,W_A,V_B,W_B$ are unitary and the matrices $\Sigma_A,\Sigma_B$ are diagonal with non-negative diagonal entries.
First, the easy direction: suppose that $A = BU$. Then $$ AA^* = (BU)(BU)^* = BUU^*B^* = BIB^* = BB^*. $$
Conversely, suppose that $AA^* = BB^*$. In terms of the SVD, this gives us $$ V_A\Sigma_A^2 V_A^* = V_B\Sigma_B^2 W_B^* $$ This is an equality of two positive semidefinite matrices. Because positive semidefinite matrices have a unique positive semidefinite square root, we can "take the square root of both sides" to conclude that $$ V_A \Sigma_A V_A^* = V_B\Sigma_B V_B^*. $$ Thus, we have \begin{align} A &= V_A \Sigma_A W_A^* \\ & = V_A \Sigma_A (V_A^*V_A)W_A^* \\ & = (V_A \Sigma_A V_A^*)(V_AW_A^*) \\ & = (V_B\Sigma_B V_B^*)(V_AW_A^*) \\ & = V_B\Sigma_B (V_B^* V_AW_A^*) \\ & = V_B\Sigma_B(W_B^*W_B) (V_B^* V_AW_A^*) \\ & = (V_B\Sigma_BW_B^*)\underbrace{(W_B V_B^* V_AW_A^*)}_{U} = BU. \end{align} Because $U = W_B V_B^* V_AW_A^*$ is a product of unitary matrices, it is unitary.