Extracting sequential and nonsequential list of scores from cell array
5 ビュー (過去 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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!