a_NexExtract.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. %% create a struct with timestamps of all neurons and events
  2. %before starting:
  3. %put all nex files in the same folder
  4. %name of each file starts with "NA1" or corresponding region and rat
  5. %for water and 3 rewards sessions, "WA1" or "TH1" (all VP)
  6. %need supporting programs "readNexFile" and "myfind"
  7. clear all;clc
  8. SAVE_FLAG=1;
  9. tic
  10. address=['C:\Users\dottenh2\Documents\MATLAB\David\2Rewards Nex Files'];
  11. AF=dir([address,'\\*.nex']);
  12. Sesnum=0;
  13. for k=1:length(AF)
  14. fname=AF(k).name;
  15. [nexfile] = readNexFile([address,'\\',fname]); fprintf([fname,'\n'])
  16. Iind=myfind(nexfile.intervals,'AllFile');
  17. Sesnum=Sesnum+1;
  18. % Get all events timestamps for the selected session
  19. NUM_EVENTS=length(nexfile.events);
  20. for j=1:NUM_EVENTS
  21. evt=nexfile.events{j}.timestamps;
  22. RAW(Sesnum).Erast{j,1}=evt(find((evt>nexfile.intervals{Iind}.intStarts) & (evt<nexfile.intervals{Iind}.intEnds)));
  23. RAW(Sesnum).Einfo(j,:)={fname,nexfile.events{j}.name};
  24. end
  25. % start from neuron 1 get ready for the next session
  26. % Get the Neuron timestamps and waveforms
  27. NUM_NEURONS=length(nexfile.neurons);
  28. for j=1:NUM_NEURONS
  29. nrn=nexfile.neurons{j}.timestamps;
  30. RAW(Sesnum).Nrast{j,1}=nrn(find((nrn>nexfile.intervals{Iind}.intStarts) & (nrn<nexfile.intervals{Iind}.intEnds)));
  31. RAW(Sesnum).Ninfo(j,:)={fname,nexfile.neurons{j}.name};
  32. end
  33. RAW(Sesnum).Type=fname(1:3);
  34. end
  35. toc
  36. %% SAVING DATA
  37. if SAVE_FLAG
  38. save('RAW.mat','RAW')
  39. end
  40. fprintf('\n')
  41. toc