Array prealocation - Extra array of zeros in 3D array
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Christopher McCausland
il 2 Nov 2021
Commentato: Christopher McCausland
il 2 Nov 2021
Hi,
I have a 13 channel signal recorded over several hours. I wish to take all channels, split them into 10 second windows with a 5 second overlap and finally concatinate all channels into a 3D array (Buffer length(n), number of buffers, channels).
I have written the function below which works as intended, except my preallocate method results in an 'extra channel' of zeros, 14 rather than 13 with the 1st array containing zeros. What I think would work is windows3D = zeros(size(windows)), however I cannot call that as 'window' is generated after the pre-allocation call.
I could just go into the array after the fact and 'delete' the additonal array of zeros however this feels like cheating, is there a better way to do this?
Kind regards,
Christopher
function [windows3D] = windowGen(eegDataNorm)
% 10 second window, 50% overlap
EEG = eegDataNorm; % Short label
Fs = 200; % Sampling frequency (Hz)
windows3D = zeros(2000,5147); %Preallocate
for i = 1:size(eegDataNorm)
windows = buffer(eegDataNorm(i,:),10*Fs,5*Fs);
windows3D = cat(3,windows3D,windows);
end
end
0 Commenti
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su EEG/MEG/ECoG in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!