clear; pack;

% define parameters
dt = 3600;
w(1,:) = [3 4 5 12 13 20 21 28 29];
w(2,:) = [7 14 15 16 22 23 24 30 31];
w(3,:) = [38 39 40 46 47 48 55 56 63];
w(4,:) = [36 37 44 45 52 53 60 61 62];
w(5,:) = [34 35 41 42 43 49 50 51 58];
w(6,:) = [2 9 10 17 18 19 25 26 27];

% generate asdr
clear asdr1 t;
load('C:\Users\USER\Documents\mingfaifong\2012-09-04_fatty_MEA_6well\fatty21369_19to22DIV.mat');
bins1 = ceil(min(time)/dt)*dt:dt:floor(max(time)/dt)*dt;
asdr1 = zeros(6,length(bins1));
for i = 1:6
    t{i} = time(ismember(channel,w(i,:))==1);
    asdr1(i,:) = hist(t{i},bins1)/dt;
end

clear asdr2 t;
load('C:\Users\USER\Documents\mingfaifong\2012-09-04_fatty_MEA_6well\fatty21368_19-24DIV.mat');
bins2 = ceil(min(time)/dt)*dt:dt:floor(max(time)/dt)*dt;
asdr2 = zeros(6,length(bins2));
for i = 1:6
    t{i} = time(ismember(channel,w(i,:))==1);
    asdr2(i,:) = hist(t{i},bins2)/dt;
end

clearvars -except asdr* bins*

%% plot stuff
close all;
figure('Position',[0 0 5000 3000]);
for i = 1:6
    subplot(12,1,i)
    stairs(bins1/3600,asdr1(i,:),'-k');
    xlim([-24 112]);
%     ylim([0 115]);
%     set(gca,'XTick',0:4:max(time)/3600);
    set(gca,'XTick',-24:4:112,'TickDir','out','TickLength',[0.0025 0.025]);
    %ylabel('ASDR (Hz)');
end
for i = 1:6
    subplot(12,1,i+6)
    stairs(bins2/3600,asdr2(i,:),'-k');
    xlim([-24 112]);
%     ylim([0 115]);
%     set(gca,'XTick',0:4:max(time)/3600);
    set(gca,'XTick',-24:4:112,'TickDir','out','TickLength',[0.0025 0.025]);
    %ylabel('ASDR (Hz)');
end

export_fig('fatty_6well_asdr1hr_variable-yscale.png','-png','-transparent','-nocrop','-r300');

%xlabel('Time (hours)');