Matlab Voronoi

clear; clc;

filename = 'data.dat';

X = importdata(filename);

% X is a m by n matrix, where n is the dimension and m is the number of points

[V,C] = voronoin(X);

% V is nv by n matrix, where nv is the number of all vertices

% C is m by ? matrix, where the ith row C{i} stores all the vertex indices of cell i (enclosing point i)

% A is ? by n matrix stores all the vertex coordinates of cell i

% K is ?? by n matrix, stores all indices of each face of the cell

figure('Color','w');

plot3(X(:,1),X(:,2),X(:,3),'Marker','.','MarkerEdgeColor','b','MarkerSize',10, 'LineStyle', 'none')

axis equal

view([90 90 90])

hold

for i=1:length(C)

%if all(C{i}~=1)

A=V(C{i},:);

K=convhulln(A);

% if abs(A) < 50

patch('Vertices',A,'Faces',K,'FaceColor','g','FaceAlpha',0.5);

% end

end

Some 3D Voronoi cells of 500 points