newreadspikes.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. function [r_result, obj] = ReadSpikesFromNextChannel(obj) % palauttaa seuraavan kanavan indexes & waves etc
  2. % onko viel? elektrodeita, jotka pit?isi lukea
  3. if obj.file_finished &&...% jos oli viimeinen tai eka kanava
  4. obj.last_file >= length(obj.files) % ja jos ei ole tiedostoja jotka pit?isi lukea
  5. Finalcsv=sortrows(obj.T, 2);
  6. thefilename=strsplit(obj.getCurrentFile(), '.');
  7. thefilename=thefilename{1};
  8. writetable(Finalcsv, strcat(thefilename,'_', 'spikes.csv'));
  9. disp('All files have been read from!');
  10. r_result = [];
  11. else % ei ole eka tai vika kanava, tai on tiedostoja joista pit?isi lukea
  12. % Tarvitseeko avata uusi tiedosto
  13. if obj.file_finished&&...
  14. obj.last_file>0
  15. Finalcsv=sortrows(obj.T, 2);
  16. thefilename=strsplit(obj.getCurrentFile(), '.');
  17. thefilename=thefilename{1};
  18. writetable(Finalcsv, strcat(thefilename,'_', 'spikes.csv'));
  19. obj.T=table; %zeroing the table
  20. obj = obj.OpenNewFile();
  21. end
  22. if obj.file_finished
  23. obj = obj.OpenNewFile(); %( obj.files(obj.last_file+1) );
  24. end
  25. %Reading the channel
  26. [r_result.error,m_data, r_result.duration, r_result.chlabel] = obj.ReadAxionChannel();
  27. %disp(r_result.chlabel)
  28. obj = obj.SiirraOsoittimetSeuraavaan();
  29. if ~r_result.error
  30. % check if the channel is behaving properly or if is noisy
  31. obj.spkdetconf.par.sr = obj.samplerate;
  32. [r_result.indexes, r_result.spikes, r_result.threshold, ~, r_result.noise, ~] = DetectSpikes_Amp(m_data, obj.spkdetconf);
  33. Time=r_result.indexes;
  34. Channel=string(repmat(r_result.chlabel, numel(r_result.indexes),1));
  35. %repeating the channel label as many times %as the number
  36. %of the detected spikes. (For the table creation)
  37. TT=table(Channel, Time);
  38. obj.T=[obj.T; TT];
  39. end
  40. end
  41. end