figurewrite.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. function figurewrite(prefix,num,mode,outputdir,omitclose)
  2. % function figurewrite(prefix,num,mode,outputdir,omitclose)
  3. %
  4. % <prefix> (optional) is the filename prefix. the prefix can include in it
  5. % '%d' (or a variant thereof) for the figure number. you can pass in
  6. % a number and we automatically convert it using num2str.
  7. % default: '%d'.
  8. % <num> (optional) is a number to use instead of the figure number
  9. % <mode> (optional) is like in printnice.m. can also be a cell vector,
  10. % in which we loop over the elements. default: [1 72].
  11. % special case is -1 which means {0 [1 72]}.
  12. % <outputdir> (optional) is the directory to write to. default: pwd.
  13. % we automatically make the directory if it doesn't exist.
  14. % <omitclose> (optional) is whether to omit the closing of the figure. default: 0.
  15. %
  16. % print current figure to <prefix>.[png,eps] and then close figure.
  17. % can use in conjunction with figureprep.m.
  18. %
  19. % example:
  20. % figureprep;
  21. % scatter(randn(100,1),randn(100,1));
  22. % figurewrite;
  23. % SEE: printnice.m.
  24. % input
  25. if ~exist('prefix','var') || isempty(prefix)
  26. prefix = '%d';
  27. end
  28. if ~exist('num','var') || isempty(num)
  29. num = [];
  30. end
  31. if ~exist('mode','var') || isempty(mode)
  32. mode = [1 72];
  33. end
  34. if ~exist('outputdir','var') || isempty(outputdir)
  35. outputdir = pwd;
  36. end
  37. if ~exist('omitclose','var') || isempty(omitclose)
  38. omitclose = 0;
  39. end
  40. if isequal(mode,-1)
  41. mode = {0 [1 72]};
  42. end
  43. if ~iscell(mode)
  44. mode = {mode};
  45. end
  46. % do it
  47. for p=1:length(mode)
  48. if isempty(num)
  49. printnice([],mode{p},outputdir,prefix);
  50. else
  51. printnice([],mode{p},outputdir,sprintf(prefix,num));
  52. end
  53. end
  54. if ~omitclose
  55. close;
  56. end