필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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
Walter Roberson
Walter Roberson 2018년 1월 25일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by