% Sleep3D.m - matab script to crate 2D contour & 3D surface D-3M movie frames % clear all clc %%%% Input File %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% file2load='RR.dat'; %%%%% Main Parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% T=500.0; % sec time interval to display in one frame Tshift=10.0; % sec time shift between frames %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Movie frames will be stored in Sleep3D folder: ImageDIR='Sleep3D'; mkdir(ImageDIR); f2l=load(file2load); t=f2l(:,1); t=t-t(1); rr=f2l(:,2); scrsz = get(0,'ScreenSize'); k1=1; k2=find(t>=T,1); Kmax=2002; % max number of frames % Kmax=5; % max # of frames for k=1:Kmax t1=t(k1); t2=t(k2); t_disp=t(k1:k2); rr_disp=rr(k1:k2); y1=rr_disp(1:end-1); y2=rr_disp(2:end); figure [ctrs1, ctrs2, F, hAxes] = dscatter2(y1,y2,'PLOTTYPE','contour'); close fig1=figure('Position',... [0.05*scrsz(3) 0.05*scrsz(4) 0.8*scrsz(3) 0.89*scrsz(4)],... 'Color',[0 0 0]); colormap jet subplot(4,1,[1 2]) surf(ctrs1, ctrs2, F, 'FaceColor','interp',... 'EdgeColor','none',... 'FaceLighting','phong') xlim([0.5 1.4]) ylim([0.5 1.4]) colormap jet view(5,70) axis off subplot(4,1, 3) contour(ctrs1, ctrs2, F,'LineWidth',2,'LevelStep',0.00015) view(5,89) colormap jet xlim([0.5 1.4]) ylim([0.5 1.4]) zlim([0.0 0.001]) axis off subplot(4,1,4) plot(t_disp,rr_disp,'r','LineWidth',2.5) xlim([(min(t_disp)-70) (max(t_disp)+120)]) ylim([0.5 1.4]) axis off % capture frame here Fr1=getframe(fig1); [Im1, Im1_map]=frame2im(Fr1); im_file=[ImageDIR '\' int2str(k) '.bmp']; imwrite(Im1,im_file); clear Fr1 Im1 Im1_map im_file; close(fig1); k1=find(t>=t1+Tshift,1); k2=find(t>=t2+Tshift,1); end