function M = step3_update(S, k, LUT, M)
    for j = 1:k
        log_mask = LUT == j;
        M(j, :) = mean(S(log_mask, :), 1);
    end
end
