consolidatematdir.m 1015 B

12345678910111213141516171819202122232425262728293031323334353637
  1. function f = consolidatematdir(dir0,varsexclude)
  2. % function f = consolidatematdir(dir0,varsexclude)
  3. %
  4. % <dir0> is a path to a directory
  5. % <varsexclude> (optional) is a variable name or a cell vector of
  6. % variable names to NOT load. if [] or not supplied, load everything.
  7. %
  8. % use consolidatemat.m to load all *.mat files
  9. % in <dir0> and write the results to <dir0>.mat.
  10. % return a string that refers to the location of the written file.
  11. %
  12. % example:
  13. % mkdir('test');
  14. % a = 1; b = 2; save('test/001.mat','a','b');
  15. % a = 3; b = 4; save('test/002.mat','a','b');
  16. % consolidatematdir('test');
  17. % results = loadmulti('test.mat','results');
  18. % results(1)
  19. % results(2)
  20. % input
  21. if ~exist('varsexclude','var') || isempty(varsexclude)
  22. varsexclude = [];
  23. end
  24. % do it
  25. dir0 = matchfiles(dir0);
  26. dir0 = dir0{1};
  27. [f,file0] = stripfile(dir0);
  28. if isempty(f) % VOODOO. BE CAREFUL.
  29. pre0 = '';
  30. else
  31. pre0 = [f filesep];
  32. end
  33. consolidatemat([pre0 file0 filesep '*.mat'],[pre0 file0 '.mat'],varsexclude);
  34. f = [pre0 file0 '.mat'];