diff --git a/NPMK/NSx Utilities/saveNSx.m b/NPMK/NSx Utilities/saveNSx.m index 159cb86..58bf975 100644 --- a/NPMK/NSx Utilities/saveNSx.m +++ b/NPMK/NSx Utilities/saveNSx.m @@ -9,18 +9,36 @@ function saveNSx(NSx,varargin) % All arguments below are optional: % Filename: A complete filepath for the output file. % Default: CurrentFilename-Modified.NSx +% Filespec: Save the file using the filespec specified e.g. 2.3 or 3.0 +% Default: same as the filespec loaded -%saveNSx version = '1.0.0.0'; +%saveNSx version = '1.0.0.1'; +% Version History +% +% 1.0.0.1: +% - Added ability to save to a specific filespec +% %% % Verify FilePath and establish overwrite paramaters -if not(isempty(varargin)) - FilePath = varargin{1}; -else - FilePath = [fullfile(NSx.MetaTags.FilePath,NSx.MetaTags.Filename) '-modified' NSx.MetaTags.FileExt]; -% [File,Path] = uiputfile; -% FilePath = [fullfile(Path,NSx.MetaTags.Filename(1:end)),'-modified', NSx.MetaTags.FileExt]; +FilePath = [fullfile(NSx.MetaTags.FilePath,NSx.MetaTags.Filename) '-modified' NSx.MetaTags.FileExt]; +if length(varargin) >= 1 + if not(isempty(varargin{1})) + FilePath = varargin{1}; + end +end + +% save to a specific filespec +if length(varargin) >= 2 + if (varargin{2} == 2.3) + NSx.MetaTags.FileTypeID(1:8) = 'NEURALCD'; + NSx.MetaTags.FileSpec(1:3) = '2.3'; + end + if (varargin{2} == 3.0) + NSx.MetaTags.FileTypeID(1:8) = 'BRSMPGRP'; + NSx.MetaTags.FileSpec(1:3) = '3.0'; + end end diff --git a/NPMK/openNEV.m b/NPMK/openNEV.m index 8703b0d..a4d4c50 100644 --- a/NPMK/openNEV.m +++ b/NPMK/openNEV.m @@ -4,15 +4,15 @@ % % Opens an .nev file for reading, returns all file information in a NEV % structure. Works with File Spec 2.1 & 2.2 & 2.3 & 3.0. -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Use OUTPUT = openNEV(fname, 'noread', 'report', 'noparse', 'nowarning', +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Use OUTPUT = openNEV(fname, 'noread', 'report', 'noparse', 'nowarning', % 'nosave', 'nomat', 'uV', 'overwrite', 'direct'). -% +% % NOTE: All input arguments are optional. Input arguments may be in any order. % % fname: Name of the file to be opened. If the fname is omitted -% the user will be prompted to select a file using an open -% file user interface. +% the user will be prompted to select a file using an open +% file user interface. % DEFAULT: Will open Open File UI. % % 'noread': Will not read the spike waveforms if user passes this argument. @@ -70,24 +70,24 @@ % 'direct': Use this if you are using a CerePlex Direct system % without the typical strobe mode. This will treat the 16th % bit of the digital input as a strobe signal and report -% the remaining 15 bits as the digital input value. +% the remaining 15 bits as the digital input value. % % OUTPUT: Contains the NEV structure. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% USAGE EXAMPLE: -% +% USAGE EXAMPLE: +% % openNEV('report','read'); % % In the example above, the file dialogue will prompt for a file. A % report of the file contents will be shown. The digital data will not be -% parsed. The data needs to be in the proper format (refer below). The +% parsed. The data needs to be in the proper format (refer below). The % spike waveforms are in raw units and not in uV. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % DIGITAL PARAMETERS/MARKERS FORMAT: % -% In order for this function to parse your experimental parameters they +% In order for this function to parse your experimental parameters they % need to be in the following format: % % *ParamLabel:Parameter1=value1;Parameter2=value2;Parameter3=value3;# @@ -97,11 +97,11 @@ % % *Stimulation:StimCount=5;Duration=10;# % -% In the first example, the parameter is of type "ExpParameter". The -% parameters are, "Intensity, Duration, Trials, and PageSement." The +% In the first example, the parameter is of type "ExpParameter". The +% parameters are, "Intensity, Duration, Trials, and PageSement." The % values of those parameters are, "1.02, 400, 1, and 14," respectively. % The second example is of type "Stimulation". The name of the parameters -% are "StimCount" and "Duration" and the values are "5" and "10" +% are "StimCount" and "Duration" and the values are "5" and "10" % respectively. % ----------------------------------------------------------------------- % It can also read single value markers that follow the following format. @@ -110,7 +110,7 @@ % % EXAMPLES: *WaitSeconds=10;# OR *JuiceStatus=ON;# % -% The above line is a "Marker". The marker value is 10 in the first +% The above line is a "Marker". The marker value is 10 in the first % and it's ON in the second example. % ----------------------------------------------------------------------- % Moreover, the marker could be a single value: @@ -126,9 +126,9 @@ % with a semi-colon ';'. % % NOTE: -% Every line requires a pound-sign '#' at the very end. +% Every line requires a pound-sign '#' at the very end. % Every line requires a star sign '*' at the very beginning. If you -% use LabVIEW SendtoCerebus.vi by Kian Torab then there is no need for +% use LabVIEW SendtoCerebus.vi by Kian Torab then there is no need for % a '*' in the beginning. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -139,7 +139,7 @@ % Version History % % 4.4.0.0: -% - Major performance boost in reading NEV files when tracking data is +% - Major performance boost in reading NEV files when tracking data is % stored in the file. % % 4.4.0.2: @@ -214,7 +214,7 @@ % 6.0.0.0: January 27, 2020 % - Added support for 64-bit timestamps in NEV and NSx. % - Removed dependency on MATLAB R2016b by removing function 'contains'. -% +% % 6.1.0.0: April 16, 2020 % - Some bug fixes. (David Kluger) % @@ -335,13 +335,13 @@ %% Defining and validating variables if ~exist('fileFullPath', 'var') if exist('getFile.m', 'file') == 2 - [fileName pathName] = getFile('*.nev;*.nevm', 'Choose a NEV file...'); + [fileName pathName] = getFile('*.nev*', 'Choose a NEV file...'); else [fileName pathName] = uigetfile; end fileFullPath = [pathName fileName]; - if fileFullPath==0; - clear variables; + if fileFullPath==0; + clear variables; if nargout varargout{1} = []; end @@ -389,7 +389,7 @@ end %% Validating existance of parseCommand -if strcmpi(Flags.ParseData, 'parse') +if strcmpi(Flags.ParseData, 'parse') if exist('parseCommand.m', 'file') ~= 2 disp('This version of openNEV requires function parseCommand.m to be placed in path.'); clear variables; @@ -407,7 +407,7 @@ if exist(matPath, 'file') == 2 && strcmpi(Flags.NoMAT, 'yesmat') && strcmpi(Flags.WarningStat, 'warning') disp('MAT file corresponding to selected NEV file already exists. Loading MAT instead...'); load(matPath); - NEV.MetaTags.FilePath = fileFullPath; + NEV.MetaTags.FilePath = fileFullPath; if isempty(NEV.Data.Spikes.Waveform) && strcmpi(Flags.ReadData, 'read') && strcmpi(Flags.WarningStat, 'warning') disp('The MAT file does not waveforms. Loading NEV instead...'); else @@ -498,7 +498,7 @@ NEV.ElectrodesInfo(ElectrodeID).ConnectorBank = char(ExtendedHeader(11)+64); NEV.ElectrodesInfo(ElectrodeID).ConnectorPin = ExtendedHeader(12); df = typecast(ExtendedHeader(13:14),'int16'); - % This is a workaround for the DigitalFactor overflow in NEV + % This is a workaround for the DigitalFactor overflow in NEV % files. Remove once Central is updated if df == 21516 NEV.ElectrodesInfo(ElectrodeID).DigitalFactor = 152592.547; @@ -529,8 +529,8 @@ Mode = ExtendedHeader(25); NEV.IOLabels{Mode+1} = char(ExtendedHeader(9:24).'); clear Mode; - case 'NSASEXEV' %% Not implemented in the Cerebus firmware. - %% Needs to be updated once implemented into the + case 'NSASEXEV' %% Not implemented in the Cerebus firmware. + %% Needs to be updated once implemented into the %% firmware by Blackrock Microsystems. NEV.NSAS.Freq = typecast(ExtendedHeader(9:10),'uint16'); NEV.NSAS.DigInputConf = char(ExtendedHeader(11)); @@ -566,7 +566,7 @@ disp(['PacketID ' PacketID ' is invalid.']); disp('Please make sure this version of openNEV is compatible with your current NSP firmware.') fclose(FID); - clear variables; + clear variables; if nargout varargout{1} = []; end @@ -682,7 +682,7 @@ NEV.Data.Spikes.TimeStamp = Timestamp(neuralIndices); NEV.Data.Spikes.Electrode = PacketIDs(neuralIndices); clear PacketIDs; -NEV.Data.Spikes.Unit = tempClassOrReason(neuralIndices); +NEV.Data.Spikes.Unit = tempClassOrReason(neuralIndices); %clear neuralIndices; NEV.Data.SerialDigitalIO.InsertionReason = tempClassOrReason(digserIndices); clear tempClassOrReason; @@ -698,7 +698,7 @@ logEventPacketIDIndices,... reconfigPacketIDIndices,... recEventPacketIDIndices]; - + if ~isempty(allExtraDataPacketIndices) % if there is any extra packets fseek(FID, Trackers.fExtendedHeader, 'bof'); fseek(FID, (Trackers.readPackets(1)-1) * Trackers.countPacketBytes, 'cof'); @@ -715,7 +715,7 @@ NEV.Data.Comments.TimeStampStarted = tempTimeStampStarted(orderOfTS); clear tempTimeStampStarted; tempText = char(tRawData(timeStampBytes+9:Trackers.countPacketBytes, commentIndices).'); NEV.Data.Comments.Text = tempText(orderOfTS,:); clear tempText; - + % Transferring NeuroMotive Events to its own structure neuroMotiveEvents = find(NEV.Data.Comments.CharSet == 255); NEV.Data.TrackingEvents.TimeStamp = NEV.Data.Comments.TimeStamp(neuroMotiveEvents); @@ -737,12 +737,12 @@ NEV.Data.Comments.TimeStampStartedSec = double(NEV.Data.Comments.TimeStampStarted)/double(NEV.MetaTags.TimeRes); NEV.Data.Comments.Text(neuroMotiveEvents,:) = []; colorFlag(neuroMotiveEvents) = []; - + % Figuring out the text color of the comments that had color NEV.Data.Comments.Color = dec2hex(NEV.Data.Comments.TimeStampStarted); NEV.Data.Comments.Color(colorFlag == 1,:) = repmat('0', size(NEV.Data.Comments.Color(colorFlag == 1,:))); - NEV.Data.Comments.TimeStampStarted(colorFlag == 0) = NEV.Data.Comments.TimeStamp(colorFlag == 0); - + NEV.Data.Comments.TimeStampStarted(colorFlag == 0) = NEV.Data.Comments.TimeStamp(colorFlag == 0); + clear commentIndices; end if ~isempty(videoSyncPacketIDIndices) @@ -770,10 +770,10 @@ tmp.NodeCount = typecast(tmp.NodeCount(:), 'uint16').'; tmp.MarkerCount = tRawData(timeStampBytes+9:timeStampBytes+10, trackingPacketIDIndices); tmp.MarkerCount = typecast(tmp.MarkerCount(:), 'uint16').'; - + tmp.rigidBodyPoints = tRawData(timeStampBytes+11:NEV.MetaTags.PacketBytes, trackingPacketIDIndices); tmp.rigidBodyPoints = reshape(typecast(tmp.rigidBodyPoints(:), 'uint16'), size(tmp.rigidBodyPoints, 1)/2, size(tmp.rigidBodyPoints, 2)); - + if (isfield(NEV, 'ObjTrackInfo')) for IDX = 1:size(NEV.ObjTrackInfo,2) emptyChar = find(NEV.ObjTrackInfo(IDX).TrackableName == 0, 1); @@ -851,7 +851,7 @@ NEV.Data.Spikes.WaveformUnit = Flags.waveformUnits; NEV.Data.Spikes.Waveform = fread(FID, [(Trackers.countPacketBytes-hOffset)/2 Trackers.readPackets(2)], ... [num2str((Trackers.countPacketBytes-hOffset)/2) '*int16=>int16'], hOffset); - NEV.Data.Spikes.Waveform(:, [digserIndices allExtraDataPacketIndices]) = []; + NEV.Data.Spikes.Waveform(:, [digserIndices allExtraDataPacketIndices]) = []; clear allExtraDataPacketIndices; if strcmpi(Flags.waveformUnits, 'uv') @@ -925,7 +925,7 @@ DShighUniqueBin = dec2bin(NEV.Data.SerialDigitalIO.UnparsedData(uniqueDShighs)); DShighUniqueDec = bin2dec(DShighUniqueBin(:,2:16)); % Removing the non-strobed-high values from SerialDigitalIO - extraMembers = setxor(uniqueDShighs, 1:length(NEV.Data.SerialDigitalIO.UnparsedData)); + extraMembers = setxor(uniqueDShighs, 1:length(NEV.Data.SerialDigitalIO.UnparsedData)); NEV.Data.SerialDigitalIO.TimeStamp(extraMembers) = []; NEV.Data.SerialDigitalIO.TimeStampSec(extraMembers) = []; NEV.Data.SerialDigitalIO.UnparsedData = DShighUniqueDec; @@ -956,7 +956,7 @@ disp(['Data Duration (min) = ' num2str(round(NEV.MetaTags.DataDuration/NEV.MetaTags.SampleRes/60))]); disp(['Packet Counts = ' num2str(Trackers.countDataPacket)]); disp(' '); - disp( '*** BASIC HEADER ***********************'); + disp( '*** BASIC HEADER ***********************'); disp(['Sample Resolution = ' num2str(NEV.MetaTags.SampleRes)]); disp(['Date and Time = ' NEV.MetaTags.DateTime]); disp(['Comment = ' NEV.MetaTags.Comment(1:64) ]); @@ -969,19 +969,19 @@ %% Saving the NEV structure as a MAT file for easy access if strcmpi(Flags.SaveFile, 'save') if exist(matPath, 'file') == 2 && strcmpi(Flags.Overwrite, 'nooverwrite') - if strcmpi(Flags.WarningStat, 'warning') + if strcmpi(Flags.WarningStat, 'warning') disp(['File ' matPath ' already exists.']); overWrite = input('Would you like to overwrite (Y/N)? ', 's'); else overWrite = 'n'; end if strcmpi(overWrite, 'y') - if strcmpi(Flags.WarningStat, 'warning') + if strcmpi(Flags.WarningStat, 'warning') disp('Saving MAT file. This may take a few seconds...'); end save(matPath, 'NEV', '-v7.3'); else - if strcmpi(Flags.WarningStat, 'warning') + if strcmpi(Flags.WarningStat, 'warning') disp('File was not overwritten.'); end end @@ -990,7 +990,7 @@ disp(['File ' matPath ' already exists.']); disp('Overwriting the old MAT file. This may take a few seconds...'); end - save(matPath, 'NEV', '-v7.3'); + save(matPath, 'NEV', '-v7.3'); else if strcmpi(Flags.WarningStat, 'warning') disp('Saving MAT file. This may take a few seconds...'); diff --git a/NPMK/openNSx.m b/NPMK/openNSx.m index 71d050a..4950c2f 100644 --- a/NPMK/openNSx.m +++ b/NPMK/openNSx.m @@ -1,15 +1,15 @@ function varargout = openNSx(varargin) % openNSx -% +% % Opens and reads an NSx file then returns all file information in a NSx % structure. Works with File Spec 2.1, 2.2, 2.3, and 3.0. % Use OUTPUT = openNSx(fname, 'read', 'report', 'e:xx:xx', 'c:xx:xx', 't:xx:xx', 'mode', 'precision', 'skipfactor', 'nozeropad'). -% +% % All input arguments are optional. Input arguments can be in any order. % % fname: Name of the file to be opened. If the fname is omitted -% the user will be prompted to select a file. +% the user will be prompted to select a file. % DEFAULT: Will open Open File UI. % % 'read': Will read the data in addition to the header information @@ -57,11 +57,11 @@ % length of data the program will exit with an errorNS % message. If the end time is greater than the length of % data the end packet will be selected for end of data. The -% user can specify the start and end values by comma +% user can specify the start and end values by comma % (e.g. [20,50]) or by a colon (e.g. [20:50]). To use this % argument the user must specify the [electrodes] or the % interval will be used for [electrodes] automatically. -% This field needs to be preceded by the prefix 't:'. +% This field needs to be preceded by the prefix 't:'. % Note that if 'mode' is 'sample' the start duration cannot % be less than 1. The duration is inclusive. % See example for more details. @@ -86,11 +86,11 @@ % 'double' the NSx data will be read as 'double' and if set % to 'short', the NSx data will be read as 'int16' data % type. While reading the file as 'short' may have a much -% smaller memory footprint and a faster read time, some -% post data analysis such as multiplying the signal by a -% factor that will make the data larger than (-32,768 to -% 32,767 -- refer to MATLAB documentation for more -% information) may result in unexpected behavior. +% smaller memory footprint and a faster read time, some +% post data analysis such as multiplying the signal by a +% factor that will make the data larger than (-32,768 to +% 32,767 -- refer to MATLAB documentation for more +% information) may result in unexpected behavior. % Always use caution when using short. If you are not sure % of what to use then do not specify this option. % DEFAULT: will read data in 'int16'. @@ -108,7 +108,7 @@ % the version number of the function without reading any % data files. % -% 'zeropad': It will zeropad the data to compensate for the non-zero +% 'zeropad': It will zeropad the data to compensate for the non-zero % start time. % DEFAULT: does not zeropad the loaded data. % @@ -119,7 +119,7 @@ % % OUTPUT: Contains the NSx structure. % -% Example 1: +% Example 1: % openNSx('report','read','c:\data\sample.ns5', 'e:15:30', 't:3:10','min', 'p:short', 's:5'); % % or equivalently @@ -127,7 +127,7 @@ % % In the example above, the file c:\data\sample.ns5 will be used. A % report of the file contents will be shown. The data will be read from -% electrodes 15 through 50 in the 3-10 minute time interval. A decimated +% electrodes 15 through 50 in the 3-10 minute time interval. A decimated % version of the datafile will be read, where only every 5th sample is read. % If any of the arguments above are omitted the default values will be used. % @@ -135,8 +135,8 @@ % openNSx('read','c:15:30'); % % In the example above, the file user will be prompted for the file. The -% file will be read using 'int16' precision as default. All time points -% of Only channels 15 through 30 will be read. If any of the arguments +% file will be read using 'int16' precision as default. All time points +% of Only channels 15 through 30 will be read. If any of the arguments % above are omitted the default values will be used. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -249,7 +249,7 @@ % - Added support for 64-bit timestamps in NEV and NSx. % % 7.1.0.0: April 14, 2020 -% - Added option to load the data without zero padding to compensate for +% - Added option to load the data without zero padding to compensate for % a non-zero start time. (David Kluger) % - Bug fixes and documentation updates (David Kluger) % @@ -258,16 +258,16 @@ % % 7.3.0.0: September 11, 2020 % - Fixed a bug related to fread and MATLAB 2020a. -% - Gives a warning about FileSpec 3.0 and gives the user options for how +% - Gives a warning about FileSpec 3.0 and gives the user options for how % to proceed. % - Added a warning about the data unit and that by default it in the % unit of 250 nV or 1/4 �V. % - If the units are in "raw", ths correct information is now written to -% the electrodes header: 250 nV (raw). +% the electrodes header: 250 nV (raw). % % 7.3.1.0: October 2, 2020 -% - If the units are in �V (openNSx('uv'), ths correct information is now -% written to the electrodes header: 1000 nV (raw). +% - If the units are in �V (openNSx('uv'), ths correct information is now +% written to the electrodes header: 1000 nV (raw). % % 7.3.2.0: October 23, 2020 % - Fixed a typo. @@ -293,6 +293,9 @@ % 7.4.4.0: April 1, 2023 % - Accounts for many segments in files for clock drift correction % - Changed 'zeropad' default behavior to be 'no' +% +% 7.4.5.0: October 5, 2023 +% - Bank numbers on new files are not alpha which causes problems on save %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Defining the NSx data structure and sub-branches. @@ -428,8 +431,8 @@ fname = inputArgument; if exist(fname, 'file') ~= 2 disp('The file does not exist.'); - if nargout; - varargout{1} = -1; + if nargout; + varargout{1} = -1; end return; end @@ -445,7 +448,7 @@ %% Popup the Open File UI. Also, process the file name, path, and extension % for later use, and validate the entry. if ~exist('fname', 'var') - [fname, path] = getFile('*.ns1;*.ns2;*.ns3;*.ns4;*.ns5;*.ns6;*.ns6m', 'Choose an NSx file...'); + [fname, path] = getFile('*.ns*', 'Choose an NSx file...'); if fname == 0 disp('No file was selected.'); if nargout; varargout{1} = -1; end @@ -462,7 +465,7 @@ end if fname==0 if nargout; varargout{1} = -1; end - return; + return; end %% Loading .x files for multiNSP configuration @@ -506,10 +509,8 @@ disp(['openNSx ' NSx.MetaTags.openNSxver]); end - - %% Reading Basic Header from file into NSx structure. -FID = fopen([path fname], 'r', 'ieee-le'); +FID = fopen([path fname], 'r', 'ieee-le'); fileFullPath = fullfile(path, fname); [NSx.MetaTags.FilePath, NSx.MetaTags.Filename, NSx.MetaTags.FileExt] = fileparts(fileFullPath); @@ -546,10 +547,10 @@ elseif strcmpi(NSx.MetaTags.FileTypeID, 'BRSMPGRP') timeStampBytes = 8; end - + %% Removing extra garbage characters from the Comment field. - NSx.MetaTags.Comment(find(NSx.MetaTags.Comment==0,1):end) = 0; - + NSx.MetaTags.Comment(find(NSx.MetaTags.Comment==0,1):end) = 0; + %% Populating extended header information for headerIDX = 1:ChannelCount offset = double((headerIDX-1)*ExtHeaderLength); @@ -558,11 +559,11 @@ disp('extended header not supported'); fclose(FID); if nargout; varargout{1} = -1; end - return; + return; end NSx.ElectrodesInfo(headerIDX).ElectrodeID = typecast(ExtendedHeader((3:4)+offset), 'uint16'); NSx.ElectrodesInfo(headerIDX).Label = char(ExtendedHeader((5:20)+offset))'; - NSx.ElectrodesInfo(headerIDX).ConnectorBank = char(ExtendedHeader(21+offset) + ('A' - 1)); + NSx.ElectrodesInfo(headerIDX).ConnectorBank = ExtendedHeader(21+offset); NSx.ElectrodesInfo(headerIDX).ConnectorPin = ExtendedHeader(22+offset); NSx.ElectrodesInfo(headerIDX).MinDigiValue = typecast(ExtendedHeader((23:24)+offset), 'int16'); NSx.ElectrodesInfo(headerIDX).MaxDigiValue = typecast(ExtendedHeader((25:26)+offset), 'int16'); @@ -722,7 +723,7 @@ %% Added by NH - Feb 19, 2014 -% Create incrementing loop to skip from dataheader to dataheader and +% Create incrementing loop to skip from dataheader to dataheader and % collect the dataheader data in individual cells headerCount = 0; % Adding logic for Central v7.6 clock drift - DK 20230303 @@ -816,7 +817,7 @@ % the data read. % DEBUG: This is not needed since the same length of data is to be % read. -EndPacket = EndPacket / skipFactor; +EndPacket = EndPacket / skipFactor; % Finding which data segment the StartPacket is falling in-between segmentCounters = []; @@ -867,7 +868,7 @@ end DataLength = EndPacket - StartPacket + 1; - + % from now StartPacket and EndPacket are in terms of Samples and are zero-based clear TimeScale @@ -883,7 +884,7 @@ % Skip the file to the beginning of the time requsted, if not 0 fseek(FID, (segmentStartPacket(dataIDX) - 1) * 2 * ChannelCount, 'cof'); % Skip the file to the first channel to read - fseek(FID, (find(NSx.MetaTags.ChannelID == min(userRequestedChannels))-1) * 2, 'cof'); + fseek(FID, (find(NSx.MetaTags.ChannelID == min(userRequestedChannels))-1) * 2, 'cof'); % Read data NSx.Data{size(NSx.Data,2)+1} = fread(FID, [numChansToRead segmentDataPoints(dataIDX)], [num2str(numChansToRead) precisionType], double((ChannelCount-numChansToRead)*2 + ChannelCount*(skipFactor-1)*2)); end @@ -895,7 +896,7 @@ % Skip the file to the beginning of the time requsted, if not 0 fseek(FID, (StartPacket - 1) * 2 * ChannelCount, 'cof'); % Skip the file to the first channel to read - fseek(FID, (find(NSx.MetaTags.ChannelID == min(userRequestedChannels))-1) * 2, 'cof'); + fseek(FID, (find(NSx.MetaTags.ChannelID == min(userRequestedChannels))-1) * 2, 'cof'); % Read data NSx.Data = fread(FID, [numChansToRead DataLength], [num2str(numChansToRead) precisionType], double((ChannelCount-numChansToRead)*2 + ChannelCount*(skipFactor-1)*2)); end @@ -931,7 +932,7 @@ % capture this - DK 20230303 % channelThatWereRead = min(userRequestedChanRow):max(userRequestedChanRow); % if ~isempty(setdiff(channelThatWereRead,userRequestedChanRow)) -% deleteChannels = setdiff(channelThatWereRead, userRequestedChanRow) - min(userRequestedChanRow) + 1; +% deleteChannels = setdiff(channelThatWereRead, userRequestedChanRow) - min(userRequestedChanRow) + 1; % if NSx.RawData.PausedFile % for segIDX = 1:size(NSx.Data,2) % NSx.Data{segIDX}(deleteChannels,:) = []; @@ -1005,7 +1006,6 @@ end end - %% Adjusting for the data's unit. if strcmpi(waveformUnits, 'uV') if iscell(NSx.Data) % Contribution by Michele Cox @ Vanderbilt