xPartitions = linspace(min(x), max(x),50);
yPartitions = linspace(min(y), max(y),100);
zPartitions = linspace(min(z), max(z), 400);
xWidth = diff(xPartitioned(1:2));
yWidth = diff(yPartitioned(1:2));
zWidth = diff(zPartitioned(1:2));
wPartitioned = zeros(50*100*400,1);
xPartitioned = zeros(50*100*400,1);
yPartitioned = zeros(50*100*400,1);
zPartitioned = zeros(50*100*400,1);
for iX=xPartitions
for iY=yPartitions
for iZ=zPartitions
index = (x >= iX - xWidth/2 & x <= iX + xWidth /2) & ...
(y >= iY - yWidth/2 & y <= iY + yWidth/2 ) & ...
(z >= iZ - zWidth/2 & z <= iZ + zWidth/2 );
xPartitioned = mean(x(index));
yPartitioned = mean(y(index));
zPartitioned = mean(z(index));
wPartitioned = mean(w(index));
end
end
end
index2 = isnan(xPartitioned);
xPartitioned(index2) = [];
yPartitioned(index2) = [];
zPartitioned(index2) = [];
wPartitioned(index2) = [];
save('data.mat', 'xPartitioned', 'yPartitioned', 'zPartitioned', 'wPartitioned');
scatter3(xPartitioned, yPartitioned, zPartitioned,[], wPartitioned,'.');