Borrar filtros
Borrar filtros

Trouble writing loop for pulling data out of separate files, rejecting data points, and saving into new file

1 visualización (últimos 30 días)
I'm trying to pull one row of data out of a struct within files of different names(that are named according to a scheme represented by fileId below), reject some data points(which come from a different file with the same naming scheme), and save the data into a .mat file, so that all the data from the row of interest from each file is saved in one place. I'm having trouble constructing the loop so that it works. My code is below.
n =[];
fileId=[5 8 11 15 18 19 21 25 27 31 35 36 38 42 43];%length is 15
out={};
load('loop_test.mat')
for m=1:15
for n=fileId
filename=sprintf('Subject%d.mat',n);
load(filename);
filename2=sprintf('EEGrej%d.mat',n);
load(filename2);
refEEG = EEG.data(8,:);%EEG is a struct within Subject%d.mat
bad_times = [];
for fill = 1:size(rej,1)%rej corresponds to the rejection indices in EEGrejection%d.mat
bad_times = [bad_times round(rej(fill,1)):round(rej(fill,2))];
end
bad_times = unique(bad_times);%takes out non-unique values
refEEG(bad_times) = [];
out{1,m}=refEEG;
save('loop_test.mat','out','-append')
end
end
When I run it I get this error: Matrix index is out of range for deletion.
Error in looptest (line 21) refEEG(bad_times) = [];
But if I do this processing individually, it works. In my workspace filename and filename two end up having different fileID's and 'out' is only populated with data from one file.
  4 comentarios
Walter Roberson
Walter Roberson el 25 de En. de 2018
No, the round function ensures that rej columns correspond to integers. We as outsiders have no reason to believe that the integers will all happen to be valid row numbers. The numbers might include non-positives or might include values greater than the number of rows.
I suggest you
dbstop in error
and run. When it stops, examine bad_times to see what values are present and from there trace back in rej to see where they came from.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by