Extracting sequential and nonsequential list of scores from cell array
조회 수: 1 (최근 30일)
이전 댓글 표시
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
2023년 7월 19일
Hi,
Can you confirm what results are you expecting for test 2 and 3 in valid_sequence?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!