Extracting sequential and nonsequential list of scores from cell array

1 view (last 30 days)
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 Comments
Menika
Menika on 19 Jul 2023
Hi,
Can you confirm what results are you expecting for test 2 and 3 in valid_sequence?
nines
nines on 19 Jul 2023
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

Sign in to comment.

Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!