For vectors, Sn(X) is the scale estimator of the elements in X. For
matrices, Sn(X) is a row vector containing the scale estimator value of
each column. For 3D arrays, Sn(X) is the robust scale estimator of the
elements along the first non-singleton dimension of X.

Sn(X,dim) takes the robust estimator along the dimension dim of X.

$Sn= cn \times c \times med_i { med_j |x_i-x_j|}$, $i=1,2, ...n$, $j=1, 2, ..., n$.

For each $i$ we compute the median of $|x_i-x_j|$, $j=1, 2, ..., n$.

This yields $n$ numbers, the median of which gives the final estimate of
$S_n$. This estimator is the robust version of Gini's average difference,
which one would obtain when replacing medians by averages
More in detail $Sn = cn \times c \times lomed_i { highmed_j
|x_i-x_j|}$, $i=1,2, ...n$, $j=1, 2, ..., n$, where $lomed$ (low
median) is $[(n+1)/2]$-th order statistic out of $n$ numbers) and
$himed$ (high median) is the $([n/2]+1)$-th order statistic out of the
$n$ numbers. $c$ is the so called asymptotic consistency factor and is
equal to 1.1926 while $cn$ is a finite sample correction factor to make
the estimator unbiased.