%connect photodetector to AIN0 on LabJack
%Press control-c to stop
clear;
FID1 = fopen('test21.dat','w');
FID2 = fopen('test22.dat','w');

h=load_labjack;
tic
for j = 1:3000; %changed this value to 300 and was 3000    
    yy(j) = lj_get(h);
    xx(j) = j;
    fprintf(1   , '%10.0f %10.4f\n', xx(j), yy(j));
    fprintf(FID1, '%10.0f\t%10.4f\n', xx(j), yy(j));
    %fprintf(FID1, '%10.0f\n', xx(j));
    %fprintf(FID2, '%10.4f\n', yy(j));
    pause(.02); % changing the time interval
    lj_step(h);
    %lj_step(h); % adding an extra step
    data=[xx;yy]'; %  1K entries Matrix that contains the data d= .7 cm
    %data2=[xx;yy]'; %  1K entries Matrix that contains the data d= 36.5 cm
    plot(xx,yy);
    grid on;
    %figure;
end
t=toc
%figure;
A4=[yy]';
%save -ascii -tabs lab3.txt data
    fclose(FID1);
    fclose(FID2);
% plot(data1_d(:,1),data1_d(:,2))
dlmwrite('test23.dat',data,'\t');