% merge subplots
% do >> handle=[];z=1;for jj=1:number_figures_to_merge
% handle(z,1)=[figure(jj)];z=z+1;end
% then pass handle to this function graph_merge_subplots(handle,rc);
% where rc is rows and columns
% see graph_set_subplot_positions for fixing ylabels and positions
function graph_merge_subplots(range,rc);
handle=[];z=1;for jj=range;handle(z,1)=[figure(jj)];z=z+1;end
tmp=get(handle(1),'Children');
if nargin<3
c=length(tmp);
r=length(handle);
end
lh=length(handle);
r=rc(1);
c=rc(2);
 hf2=figure(200);
 z=1;
for jj=1:lh;

    
%     
%        figure(100);
%    plot(rand(100,1));grid
%    title('some title'),xlabel('time');ylabel('amplitude')
   hax1=get(handle(jj),'Children');
   tt=[1:c:r*c];

  for kk=length(hax1):-1:1;
   s1=subplot(r,c,z);
   pos=get(s1,'Position');
   delete(s1);
   hax2=copyobj(hax1(kk),hf2);
   set(hax2, 'Position', pos);
   if z<=(r*c-c)
   hh=get(hax2,'Children');
   for uu=1:length(hh);
       if isprop(hh(uu),'String')
   set(hh(uu),'String','');
       end
   end
   end
   % put title in y axis of first column
   if any(z==tt);
   if isempty(get(get(hax2,'Title'),'String'))
       if ~isempty(get(get(hax2,'Parent'),'name'))
%    title(get(get(hax2,'Parent'),'name'))
   ylabel(get(get(hax2,'Parent'),'name'))
   
       end
   else
       try
%        title((get(get(hax1,'Title'),'String')))
       ylabel((get(get(hax1,'Title'),'String')))
%        title('')
       catch
           keyboard
       end
   end
   end
   z=z+1;
  end
end
    
