check_consistency.m 932 B

12345678910111213141516171819202122232425262728293031
  1. function [N,C]=check_consistency(data1,data2,sp)
  2. % Helper routine to check consistency of data dimensions
  3. % Usage: [N,C]=check_consistency(data1,data2,sp)
  4. % Inputs:
  5. % data1 - first dataset
  6. % data2 - second dataset
  7. % sp - optional argument to be input as 1 when one of the two data sets is
  8. % spikes times stored as a 1d array.
  9. % Outputs:
  10. % Dimensions of the datasets - data1 or data2 (note that
  11. % routine stops with an error message if dimensions don't match - [N,C]
  12. % N left empty for structure arrays
  13. N1=[]; N2=[];
  14. if nargin < 3 || isempty(sp); sp=0; end;
  15. if isstruct(data1);
  16. C1=length(data1);
  17. else
  18. [N1,C1]=size(data1);
  19. end;
  20. if isstruct(data2);
  21. C2=length(data2);
  22. else
  23. [N2,C2]=size(data2);
  24. end;
  25. if C1~=C2; error('inconsistent dimensions'); end;
  26. if sp==0;
  27. if ~isstruct(data1) && ~isstruct(data2);
  28. if N1~=N2; error('inconsistent dimensions'); end;
  29. end;
  30. end;
  31. N=N1; C=C1;