Extracting sequential and nonsequential list of scores from cell array

2 次查看(过去 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
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 中查找有关 Data Import and Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by