Hello!
I'm still working on some code I have asked about in previous questions. All seems to be going well except in my output I keep getting zeros unexpectedly and I can't seem to figure out why
The code opens data, uses accumarray to place the data into vectors and then writes the output of the vectors into a matrix. For some reason I seem to get random rows of zero in this matrix – and I cant seem to find out why
The code is below:
% Cycle through files rownum = 1;
for f = 1: numberOfFiles resFileName = fullfile(res_files,baseFileNames(f).name) Name = baseFileNames(f).name rawData = importdata(resFileName,' ');
timeData = rawData.data(:,1); ampData = rawData.data(:,2); PIDget = Name(3:5) PID = str2num(PIDget) Task1.PID{f} = PID; binnum = 1 + floor(timeData(:) / 39); Task1.Amp(f).trial = accumarray( binnum, ampData(:), [], @(V) {V}) Task1.Time(f).trial = accumarray( binnum, timeData(:), [], @(V) {V}) numtrial = numel(Task1.Amp(f).trial)% for trialnum = 1:numel(Task1.Amp(f).trial)
binnum(end)for trialnum = 1:binnum(end) for numbers = 1:numel(Task1.Amp(f).trial{trialnum}) timedata = Task1.Time(f).trial{trialnum}(numbers);ampdata = Task1.Amp(f).trial{trialnum}(numbers); DATA_raw(rownum,1) = PID; DATA_raw(rownum,2) = trialnum; DATA_raw(rownum,3) = timedata; DATA_raw(rownum,4) = ampdata; rownum = rownum + numbers; endendend
The output data file DATA_Raw looks like this…
2 3 114.080000000000 0.2180000000000000 0 0 00 0 0 00 0 0 02 4 120.260000000000 0.0350000000000000
Where are these zero's coming from???
Thanks, ML
Best Answer