Home > NoiseTools > nt_mat2trial.m

# nt_mat2trial

## PURPOSE

[y]=nt_trial2mat(x) - convert 3D matrix to trial cell array

## SYNOPSIS

function [y]=nt_mat2trial(x,w)

## DESCRIPTION

    [y]=nt_trial2mat(x) - convert 3D matrix to trial cell array

      y: trial array (each trial is channels * samples)

      x: matrix (samples * channels * trials)
      w: weights (samples * 1 * trials)

     Weights, if provided, control the size of each trial.

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 function [y]=nt_mat2trial(x,w)
    0002 %[y]=nt_trial2mat(x) - convert 3D matrix to trial cell array
    0003 %
    0004 %  y: trial array (each trial is channels * samples)
    0005 %
    0006 %  x: matrix (samples * channels * trials)
    0007 %  w: weights (samples * 1 * trials)
    0008 %
    0009 % Weights, if provided, control the size of each trial.
    0010
    0011 if nargin<2; w=[]; end
    0012
    0013 [nsamples,nchans,ntrials]=size(x);
    0014 y={};
    0015 if isempty(w)
    0016     for k=1:ntrials
    0017         y{k}=x(:,:,k)';
    0018     end
    0019 else
    0020     for k=1:ntrials
    0021         y{k}=x(1:max(find(w(:,1,k))),:,k)';
    0022     end
    0023 end