Add a comment to an eps file created with saveas

2 views (last 30 days)
Emily on 23 Mar 2021
Commented: Emily on 29 Nov 2021
I have many scripts that read my data, plot it, and save the figure as an encapsulated postscript file (used to use export_fig from the file exchange, now am using saveas). Sometimes I want to recreate a figure, and have to figure out which script generated it. Is there a way for my script to programmatically add a comment to the preamble of the postscript file so I can leave myself clues for recreating it? The head of my .eps file looks like this:
%!PS-Adobe-3.0 EPSF-3.0
%%Creator: (MATLAB, The Mathworks, Inc. Version \(R2019a\). Operating System: Linux)
%%Title: /home/etownsen/quantumplasmonics/Record/Disorder/2QE1by12w6/EnergyInitBasis2872QEsNotResw1stPl1by12w6Coul1tb-1EQE112EQE212ydHndCDa0.01Db0.3Lhop0.2Seed4.eps
%%CreationDate: 2021-03-10T10:44:35
%%Pages: (atend)
%%BoundingBox: 85 28 861 514
%%LanguageLevel: 3
So it seems likely that adding info to the "Creator" line would not hurt the eps file, and probably I can even safely add a line like
%%Script: /here/something.m
Ideally it gets written when I create the file, but it might also be okay to add it after creating. I'd like the comment to contain the name (and path) of the script that created the eps. (And maybe the line number? but that's getting greedy.)
Emily on 29 Nov 2021
This solution works on the windows machine. On the linux machine splitting into lines is accomplished by
FileContents = regexp(FileContents, '\n', 'split');
(the search term is just '\n' rather than '\r\n'.)

Sign in to comment.

Answers (0)


Find more on Printing and Saving in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!