change_row_to_column.m 969 B

1234567891011121314151617181920212223242526272829303132
  1. function data=change_row_to_column(data)
  2. % Helper routine to transform 1d arrays into column vectors that are needed
  3. % by other routines in Chronux
  4. %
  5. % Usage: data=change_row_to_column(data)
  6. %
  7. % Inputs:
  8. % data -- required. If data is a matrix, it is assumed that it is of the
  9. % form samples x channels/trials and it is returned without change. If it
  10. % is a vector, it is transformed to a column vector. If it is a struct
  11. % array of dimension 1, it is again returned as a column vector. If it is a
  12. % struct array with multiple dimensions, it is returned without change
  13. % Note that the routine only looks at the first field of a struct array.
  14. %
  15. % Ouputs:
  16. % data (in the form samples x channels/trials)
  17. %
  18. dtmp=[];
  19. if isstruct(data);
  20. C=length(data);
  21. if C==1;
  22. fnames=fieldnames(data);
  23. eval(['dtmp=data.' fnames{1} ';'])
  24. data=dtmp(:);
  25. end
  26. else
  27. [N,C]=size(data);
  28. if N==1 || C==1;
  29. data=data(:);
  30. end;
  31. end;