function [IDXs,Cs,Ds] = labsplitc( tri_bil,IDX,cluster,split )
%Uses preexistent cluster data to split existing clusters into subclusters.
%Calls nrows from previous functions in order to work.
global nrows
IDXL = (IDX == cluster);
dlab=tri_bil(:,:,4);
IDXt1 = dlab(:,2).*IDXL;
IDXt2 = dlab(:,3).*IDXL;
i1=sum(IDXt1)./sum(IDXt1~=0);
i2=sum(IDXt2)./sum(IDXt2~=0);
IDXt1(IDXt1 == 0)=i1;
IDXt2(IDXt2 == 0)=i2;
IDXt=[IDXt1 IDXt2];
[IDXs,Cs,sumds,Ds]=kmeans(IDXt,split,'replicates',5);
figure
hold on
xlabel('a*')
ylabel('b*')
str=sprintf('Cluster %d split by %d subclusters',cluster,split);
title(str)
for n=1:split
    IDXr = (IDXs == n);
    scatter(IDXr.*IDXt(:,1),IDXr.*IDXt(:,2),1);
end
hold off
IDXs=IDXs.*IDXL;
rIDXs=reshape(IDXs,nrows,[]);
rIDXs=mat2gray(rIDXs);
figure
imshow(rIDXs)
str=sprintf('Map of cluster %d split by %d subclusters',cluster,split);
title(str)
end