clc

clear all

%n=4;
 

nstem = 1;

nleaf = 1;


%X=[fix(10^(n-2)*rand(num,1));fix(10^(n)*rand(num,1))]

X=[32 4 36 16 23 30 45 31 31 29]'

length_X=length(X);


X=sort(X);

Xs=num2str(X);

ind=find(Xs==' ');

Xs_1=Xs;

Xs_1(ind)='0';


stem1= Xs_1(:,1:nstem) ;

stem_vals=unique(stem1) ; 

 


num_stem=length(stem_vals);

leaf1= Xs_1(:,(nstem+1):(nstem+nleaf));


for j= 1:num_stem
    stem_vals(j,:);
    leaf=[];
    for k=1:length_X
        if stem1(k,:)==stem_vals(j,:);
    leaf=[leaf,leaf1(k,:)];
        end
  
    end
    
  
    
    STEM_LEAF(j, 1)= eval(stem_vals(j,:)) ;
     STEM_LEAF(j, 2)=eval(leaf);
     
      
%  s=sprintf('%s   %s', STEM_LEAF(j, 1),STEM_LEAF(j, 2))	  ;
 s=sprintf('%s   %s', stem_vals(j,:),leaf)	  ;
 disp(s)
     
end

% STEM_LEAF
 
 

% stem_string= diag(STEM_LEAF(:,:,1)) 
% 
% leaf_string=  diag(STEM_LEAF(:,:,2)) 
% 
% steam_num = eval(stem_string(1))


% stem0_ind=find(Xs_1(:,1:nstem)=='0')
% 
% ind_not0=find(diff(Xs_1(:,1:nstem))~='0')
% 
% 



