function c = vqlbg(d, k)
% VQLBG Vector quantization using the Linde-Buzo-Gray algorithm
%
% Inputs:
% d contains training data vectors (one per column)
% k is number of centroids required
%
% Outputs:
% c contains the result VQ codebook (k columns, one for each centroids)
z = disteu(d, c);
Now z(i, j) would be the distance between the training
vector d(:, i) and the codeword c(:, j). Next step,
for each training vector, find the closest codeword. For this, use
the Matlab function min:
[m, ind] = min(z, [], 2);
The result index vector ind contains the associated cluster
number for each training vector. So to access to all the training
vectors that belong to the cluster number j (those vectors that
are closest to the codeword c(:, j)), one can use:
d(:, find(ind == j));
c(:, j) = mean(d(:, find(ind == j)), 2);