% eda02_10
% load and plot neuse.txt dataset

% load data
D=load('neuse.txt');
t=D(:,1);
d=D(:,2);
Ls=size(d);
L=Ls(1);

% plot only these lounds
L1=500;
L2=1000;

figure(1);
clf;

% plot discharge
subplot(1,3,1);
set(gca,'LineWidth',2);
axis ij;
hold on;
plot(d(L1:L2),t(L1:L2),'k-','LineWidth',2);
title('A)');
xlabel('discharge');
ylabel('time');

% compute rate
dddt=(d(2:L)-d(1:L-1)) ./ (t(2:L)-t(1:L-1));

% plot rate
subplot(1,3,2);
set(gca,'LineWidth',2);
axis ij;
hold on;
plot(dddt(L1:L2),t(L1:L2),'k-','LineWidth',2);
title('B');
xlabel('d/dt discharge');
ylabel('time');

% compute histogram
Nh=100;
dddtmin=-500;
dddtmax=500;
bins = dddtmin + (dddtmax-dddtmin)*[0:Nh-1]'/(Nh-1);
dddth = hist(dddt,bins);
% delete first and last bins
dddth = dddth(2:Nh-1);
bins = bins(2:Nh-1);

% histogram
subplot(1,3,3);
set(gca,'LineWidth',2);
axis ij;
hold on;
plot(dddth,bins,'k-','LineWidth',2);
% plot dotted line at counts=0
a = axis;
plot( [0,a(2)]', [0,0]', 'k:','LineWidth',2);
title('C)');
xlabel('counts');
ylabel('d/dt discharge');


