Home > NoiseTools > nt_fold.m

nt_fold

PURPOSE ^

y=fold(x,epochsize) - fold 2D to 3D

SYNOPSIS ^

function x=fold(x,N)

DESCRIPTION ^

y=fold(x,epochsize) - fold 2D to 3D 

  y: 3D matrix of (time * channel * trial)

  x: 2D matrix of concatentated data (time * channel)
  epochsize: number of samples in each trial

 NoiseTools

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function x=fold(x,N)
0002 %y=fold(x,epochsize) - fold 2D to 3D
0003 %
0004 %  y: 3D matrix of (time * channel * trial)
0005 %
0006 %  x: 2D matrix of concatentated data (time * channel)
0007 %  epochsize: number of samples in each trial
0008 %
0009 % NoiseTools
0010 
0011 %nt_greetings;
0012 
0013 if ndims(x)==3; 
0014     x=nt_unfold(x); % in case it was already folded
0015 end
0016 
0017 if ~isempty(x)
0018     nepochs=size(x,1)/N;
0019     if nepochs~=round(nepochs)
0020         warning('nsamples not multiple of epoch size, truncating...');
0021         nepochs=floor(nepochs);
0022         x=x(1:N*nepochs,:);
0023     end
0024     if nepochs>1
0025         x=permute(reshape(x,[N, size(x,1)/N, size(x,2)]), [1 3 2]);
0026     else
0027         x=x;
0028     end
0029 end

Generated on Sat 29-Apr-2023 17:15:46 by m2html © 2005