3D array, remove columns where second array == -1
3 views (last 30 days)
Christopher McCausland on 10 Nov 2021
I am curently processing 13 channels of PSG data. I take my data and create 10 second buffers with 5 second overlaps for the length of the data. This returns a 3D array "windows3D" which is 2000*5147*13 (buffer width * no. of buffers * channels)
I have a second array called "truthBuffer" which is 1*5147, this array tells me if the 2000 samples have been identified by a clinican as positive (1) negitive (0) or are not scored (-1). I wish to preform Machine learning on this so I wish to remove the array elements of truthBuffer which are -1 and then remove the corresponding colums from all channels of windows3D.
This should return scoredTurthBuffer as a 1*2538 array (as there are 2609 '-1' values - this part works) and assessedWindows3D as a 2000*2538*13 (where the same 2538 colums are retained for all 13 channels) this part doesn't work
This is what i,ve tried below, this works well for "scoredTruthBuffer" (1*5147 ==> 1*2538) but "assessedWindows3D" changes from 2000*5147*13 to 1*133819391 array which is not what I expect. I am expecing an array of 2000*2538*13 back.
scoredTruthBuffer = truthBuffer; % Create a mirrior of truthBuffer || creates sized array 1*5147 as expected
assessedWindows3D = windows3D; % Create a mirrior of windows3D || creates sized array 2000*5147*13 as expected
toRemove = truthBuffer == -1; % Find what elements to remove in turthBuffer || 2609 '-1' values (5147-2609 = 2538)
scoredTruthBuffer(toRemove) = ; % remove elements from truthBuffer || creates sized array 1*2538 as expected
assessedWindows3D(toRemove) = ; % remove elements from truthBuffer || creates sized array 1*133819391 UNEXPECTED, expecting 2000*2538*13
I have also tried to include a for loop to preform this task channel by channel but I get the following error;
% for i = 1:13
% for j = 1:length(truthBuffer)
% if truthBuffer == -1
% windows3D(:, j ,i) = ;
% Error given
=>> A null assignment can have only one non-colon index.
I know the error is generated by the inclusion of both 'j' and 'i' but I cannot come up with a easy way around this.
How can I return "assessedWindows3D" as a 2000*2538*13 to match the columns removed in scoredTruthBuffer?
Thanks in advance,
Dave B on 10 Nov 2021
Edited: Dave B on 10 Nov 2021
From what I can see here, you've got a logical vector called toRemove, and you want to remove columns where toRemove is true from your matrix. But you didn't specify that it was columns which you wanted removed when you tried to remove from assessedWindows3D.
Here's a simpified example:
a = [1 -1 2 -1];
toRemove = a == -1;
assessedWindows3D = rand(2, 4, 2); % smaller version of assessedWindows3D so we can see it
assessedWindows3D(:,toRemove,:) = ; % note this is indexing toRemove in the second dimension