First you may need to sort your optimization variables. Taking idea from Dr. Kalvelagen (link) & YALMIP define additional continuous variablesvariable $0 \le x,z,$$0 z$, $x$ of same domain s $y$ & $i \times i$ matrix of binary variables $p$
Basically
$x_i = p_{i,j}x_i$
$\sum_i z_{i,j} = y_j \quad \forall j$
$\sum_j z_{i,j} = x_i \quad \forall i$
$\sum_i p_{i,j} = 1$
$\sum_j p_{i,j} = 1$
$x_i \le x_{i+1}$
$z_{i,j} \le Mp_{i,j}$
Median = $x_{I+1\over2}$ if $I$ or $J$ is odd, else ${x_{k}+x_{k+1}}\over 2$ where $k={{I+1}\over2}$$k={{I}\over2}$