When i try to link a filedtrip structure using "Review RAW file" I get an array out of bounds error in the function out_fwrite_bst.m at line 68
I use the current 24-Apr-2020 version, and Matlab 2019b on Windows 10
File I used was 32ch at 10kHz for ~700s ->1.7GB
error seem to be originating from the automatic epoching
Error can be solved by changing line 68 of out_fwrite_bst to:
"bst_write_epoch(sFile, sfid, epochsToWrite(i), iTimeWrite, ChannelsRange, F(:, min(iNewF, size(F,2))));"
The fix you propose may work (= not crash), but does not produce the expected result: it saturates the list of indices in iNewF, which causes to copy the last value multiple times at the end of the segment written to the file.
What we should do instead is to fix the definition of the iNewF list of indices.
Could you please share some short example data file with which we could reproduce and debug this issue?
Try to extract only a few seconds of data from this FieldTrip structure
Make sure you get exactly the same error when trying to link it into Brainstorm
Upload it somewhere (dropbox, google drive, wetransfer...)
The error is not like I first expected due to the epoching with an incomplete last epoch.
It seems the be originating from a not strictly uniform timevector. Does Brainstorm support this?
Otherwise its completely fine for me to resample my data to a uniform time.
Example data can be generated with the following script:
%% Data Generation Scripts for out_fwrite_bst.m error
Fs =10e3;
data=[];
NCH = 32;
T_sig = 1.1234;
sig = rand(NCH,Fs*T_sig);
data.label = cellstr(string(1:NCH)); % cell-array containing strings, Nchan*1
data.fsample = Fs; % sampling frequency in Hz, single number
data.trial{1} = sig; % cell-array containing a data matrix for each trial (1 X Ntrial), each data matrix is a Nchan*Nsamples matrix
FT_Error ='working';
switch FT_Error
case 'working'
data.time{1} =(0:(length(sig))-1)./Fs; % cell-array containing a time axis for each
case 'error'
data.time{1} =(0:(length(sig)))./Fs; % cell-array containing a time axis for each
data.time{1}(99) = [];
end
data.sampleinfo=[1,length(sig)];
data.label = data_ft.label;
save('./Test_FT.mat', 'data')