How to make this code work? Forel algorithm

1 次查看(过去 30 天)
function [clusters, centers] = forel(X, r)
clusters = {};
centers = [];
X = {2 3 4};
r = [2];
%weights = ones(size(X,2), 1);
x_idx = (1:size(X,1));
i = 0;
while(length(x_idx) > 0)
%find distances to centers of clusters
new_len = 0;
%init new cluster
if (new_len == 0)
i = i + 1;
center = X(x_idx(1), :);
clusters(i) = {x_idx(1)};
x_idx(1) = [];
endif
last_center = center + 1;
%loop update cluster
while (center ~= last_center)
%save last centers
last_center = center;
%dists = w_euclidean_dist(X(x_idx,:), center, weights);
dists = sqrt(sum(bsxfun(@minus, x_idx, center).^2, 2));
x_label = find(dists <= r);
new_len = length(x_label);
%add idxs to the cluster
clusters(i) = [cell2mat(clusters(i)), x_idx(x_label)];
%find new center
center = mean(X(cell2mat(clusters(i)), :));
%remove added elements
x_idx(x_label) = [];
endwhile
%update centers
centers(i,:) = center;
endwhile
end
What should be changed or what values should be specified in the code?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Manage Products 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by