That is essentially what I had, although i had everything in array format so i could inspect the data for each iteration. Yours is cleaner, so I hope you don't mind I've modified it a bit. I replaced the for() loop with the Loc function as it might be more efficient in case anyone else is using this for large data sets. (Disclaimer, I've used this function only once or twice... hopefully it is the right choice.)
When I ran your function and mine, I found that it converged in 1 iteration with a mean of 5.339 and a sigma of 1.044. The paper seems to indicate it would take several iterations. I thought they meant even for this data set but maybe they were generalizing. They go on to say that the Huber estimated mean is 5.36 and sigma is 1.15. I was not able to reproduce that estimated mean, but when I replaced 'x' data with x_orig (original data) in each iteration, I got a mean of 5.386 and sigma of 1.1459. You can see the line in the code below to enable / disable this. This doesn't really feel like the correct way to iterate something, but I'm not really sure where I've gone wrong in being able to compute this. Forgive the sig digits errors but I wanted to show more about the variable contents here.
From the paper:
names default to here(1);
clear log();
//Data Set in Paper
x_orig = [4.5, 4.9, 5.6, 4.2, 6.2, 5.2, 9.9];
x = [4.5, 4.9, 5.6, 4.2, 6.2, 5.2, 9.9];
//Determine Median and Robust Sigma (MAD)
mean = Quantile( .5, x );
y = Abs( x - mean );
MAD = Quantile( .5, y );
sigma = MAD * 1.5;
sigmaold = 0;
//Converge
While( Abs( sigma - sigmaold ) > 2e-16,
//x = x_orig; // try turning this on / off
x [Loc(x > (mean + 1.5 * sigma))] = mean + 1.5 * sigma;
x [Loc(x < (mean - 1.5 * sigma))] = mean - 1.5 * sigma;
meanold = mean;
sigmaold = sigma;
mean = Mean( x );
sigma = 1.134 * Std Dev( x );
show(mean, sigma);
);
Thanks,
Mike