A dummy solution is given by the function diary
which enables the storing of the matlab console output on a file.
X = [randn(20,2)+ones(20,2); randn(20,2)-ones(20,2)];
opts = statset('Display','iter');
diary('output.txt') % # Whatever is displayed from now on is saved on 'output.txt'
[cidx, ctrs] = kmeans(X, 2, 'Distance','city', ...
'Replicates',5, 'Options',opts);
diary('off') % # logging is disabled
After the execution, output.txt
will contain
iter phase num sum
1 1 40 96.442
2 1 8 79.7403
3 1 6 70.2776
...
You may want to clean the content of output.txt
at every run, otherwise it will just append the new log after the previous one.