Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

openNSxSync.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. function NSx = openNSxSync(varargin)
  2. % openNSxSync
  3. %
  4. % Opens a synced NSx file and removed the extra bit of data from the file.
  5. %
  6. % INPUT
  7. %
  8. % filename: The name of the file to be opened.
  9. % DEFAULT: The program will prompt the user to select a file.
  10. %
  11. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  12. % Kian Torab
  13. % kianblackrockmicro.com
  14. % Blackrock Microsystems
  15. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  16. % Version History
  17. %
  18. % 1.0.0.0:
  19. % - Initial release.
  20. %
  21. % 1.1.0.0: June 13, 2014
  22. % - Added the ability to open a file by passing on the file name.
  23. %
  24. % 1.1.1.0: December 3, 2014
  25. % - Fixed a minor bug.
  26. %
  27. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  28. %% Initializing varilables.
  29. for inputIDX = 1:nargin
  30. inputVar = varargin{inputIDX};
  31. if isnumeric(inputVar)
  32. if inputVar >= 1 && inputVar <= 2
  33. method = inputVar;
  34. else
  35. disp('The variable method can only be 1 (defauly) or 2. See help for more information.');
  36. NSx = -1;
  37. return;
  38. end
  39. else
  40. filename = inputVar;
  41. end
  42. end
  43. %% Openning Synced files and removing the extra piece of data
  44. if exist('filename', 'var')
  45. if exist(filename, 'file') == 2
  46. NSx = openNSx(filename);
  47. else
  48. disp('File was not found.');
  49. NSx = -1;
  50. return;
  51. end
  52. else
  53. NSx = openNSx;
  54. end
  55. %% Getting rid of the data extra bits and pieces created by the sync algorithm
  56. if iscell(NSx.Data)
  57. % Removing the extra bit of empty data
  58. NSx.Data = NSx.Data{2};
  59. NSx.MetaTags.Timestamp(1) = [];
  60. NSx.MetaTags.DataPoints(1) = [];
  61. NSx.MetaTags.DataDurationSec(1) = [];
  62. % Re-aligning what's left
  63. NSx.Data = [zeros(NSx.MetaTags.ChannelCount, floor(NSx.MetaTags.Timestamp)/NSx.MetaTags.SamplingFreq) NSx.Data];
  64. NSx.MetaTags.DataPoints = NSx.MetaTags.DataPoints - NSx.MetaTags.Timestamp;
  65. NSx.MetaTags.DataDurationSec = NSx.MetaTags.DataPoints / NSx.MetaTags.SamplingFreq;
  66. NSx.MetaTags.Timestamp = 0;
  67. end
  68. %% If user does not specify an output argument it will automatically create a structure.
  69. outputName = ['NS' NSx.MetaTags.FileExt(4)];
  70. if (nargout == 0),
  71. assignin('caller', outputName, NSx);
  72. clear all;
  73. else
  74. varargout{1} = NSx;
  75. end