Matrix indexing within a loop

조회 수: 3 (최근 30일)
Rene Sebena
Rene Sebena 2016년 11월 20일
댓글: Walter Roberson 2016년 11월 20일
Hi there, I have a script which loads epoched eog data (one after another) and identifies the bad trials (horizontal amplitudes above 95mV or bellow -95 mV). What I am just trying to add there, is a code which will be continuosly write into 8*25matrix (8 experimental conditions and 25 trials for each), which trials are good and which are bad, so if it finds eg. in the 9th trial of the first experimental condition bad trial it will write "1", and if not "0". Hope it is clear enough and thank you for your help!
for k = 1:8
% Create a mat filename, and load it into a structure called matData.
matFileName = sprintf('event_%d_chans35-38.mat', k);
if exist(matFileName, 'file')
matData = load(matFileName);
else
fprintf('File %s does not exist.\n', matFileName);
end
xf=diff(matData.dataArray(3:4,:,:),1);
xf=squeeze(xf);
EOG_threshold_min = -95;
EOG_threshold_max = 95;
% Identify trials behind the threshold
max_hor_amplitudes = max(xf); %get max amplitude for each individual trial
min_hor_amplitudes = min(xf); %get min amplitude for each individual trial
bad_max = max_hor_amplitudes > EOG_threshold_max;
bad_min = min_hor_amplitudes < EOG_threshold_min;
bad_trials_max = find(bad_max);
bad_trials_min = find(bad_min);
end

채택된 답변

Walter Roberson
Walter Roberson 2016년 11월 20일
Change
bad_trials_max = find(bad_max);
bad_trials_min = find(bad_min);
to
bad_trials_max(k, :) = bad_max;
bad_trials_min(k, :) = bad_min;
  댓글 수: 2
Rene Sebena
Rene Sebena 2016년 11월 20일
Thanks for answer, but it is not quite what I need, this will rewrite in each step within the loop the previous condition,..so at the end I just see the results from the last condition. I need output which will look like this:
Wrong = (8,25);
0 0 0 0 0 1 0 etc.....1st loop step = 1st condition
0 0 0 0 0 0 1 etc.....2nd loop step = 2nd condition
etc...
Walter Roberson
Walter Roberson 2016년 11월 20일
The indexing by k ensures that it updates the output matrix, not rewrites all of it.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by