필터 지우기
필터 지우기

Extracting sequential and nonsequential list of scores from cell array

조회 수: 6 (최근 30일)
nines
nines 2023년 7월 19일
댓글: nines 2023년 7월 19일
Hello all,
I have a list of scores where I want to extract the Wake scores and then also the NREM scores (any combination of N1, N2, N3). I only want to extract them if there are more than 7 epochs in the list of scores. I would also like the take the values if there are 7 epochs that are sequential (e.g. test 3).
When I run the following code I get the correct answer:
valid_sequences = 2 9
scores = {'N1' ' N3' 'Wake' 'Wake' 'Wake' 'Wake' 'Wake' 'Wake' 'Wake' 'N1'};
sleepStages = {'Wake', 'NREM'};
sleepStagesMap = containers.Map({'Wake', 'N1', 'N2', 'N3'}, [1 2 2 2]);
sequence_start = 1;
num_scores = numel(scores);
valid_sequences = [];
for j = 1:num_scores
stage = scores{j};
if strcmp(stage, 'Wake')
if j == num_scores
sequence_length = j - sequence_start + 1;
else
sequence_length = j - sequence_start;
end
if sequence_length >= 7
valid_sequences = [valid_sequences; sequence_start, j];
end
elseif ismember(stage, {'N1', 'N2', 'N3'})
sequence_length = j - sequence_start;
if sequence_length >= 7 && sum(ismember(scores(sequence_start:j), {'N1', 'N2', 'N3'})) >= 7
valid_sequences = [valid_sequences; sequence_start, j];
end
else
sequence_start = j;
end
end
However, when I run the same code with the following tests I get incorrect answers:
% test 2
scores = {'Wake' 'Wake' 'N1' 'N1' 'N2' 'N3' 'N2' 'N2' 'N3' 'Wake'};
valid_sequences =
1 9
1 10
% test 3
scores = {'Wake' 'Wake' 'Wake' 'Wake' 'Wake' 'Wake' 'N2' 'Wake' 'Wake' 'Wake'};
valid_sequences =
1 9
1 10
Can you help me? I've been stuck on this for a couple of days, and just keep running into the same answers. Thanks so much.
  댓글 수: 2
Menika
Menika 2023년 7월 19일
Hi,
Can you confirm what results are you expecting for test 2 and 3 in valid_sequence?
nines
nines 2023년 7월 19일
they should be:
test 2: 2 9
test 3: 1 6; 7 10
I am going to use the epochs to extract corresponding timeseries.
Ideally, it would be nice to have the following because I think it is less confusing:
test 1: 3 9
test 2: 3 9
test 3: 1 6; 8 10

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Elementary Math에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by