Creating Variable Output Filename

Hi, I have a script that generates a pdf full of plots.
I would like the output filename *.pdf file to be automatically named according to a variable which contains a date and title
How can I insert a variable filename?
This is the code which saves everything into a pdf:
ps2pdf('psfile', 'myfile.ps', 'pdffile', 'filename.pdf', 'gspapersize', 'a4')
Thanks,

 Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Jul. de 2012
psfilename = sprintf('myfile%s.ps', datestr(TheDate, 'yyyymmdd') );
ps2pdf('psfile', psfilename, 'pdffile', 'filename.pdf', 'gspapersize', 'a4')

3 comentarios

Aadil
Aadil el 31 de Jul. de 2012
Thanks, I tried this, it didn't work
I tried this instead, it works for a simple text filename but not if I want to insert a value from an array:
pfilename = ['sdsgafdsgf' '.pdf'];
ps2pdf('psfile', 'myfile.ps', 'pdffile', pfilename, 'gspapersize', 'a4')
When I try insert raw(3) - which is the value from an array containing the date:
>> raw(3)
ans =
'09/07/2012 23:22:01'
.. I get this error:
??? Error using ==> fopen
Invalid filename.
Error in ==> ps2pdf>LocalParseArgs at 199
pdf_fid = fopen(param_value,'w');
Error in ==> ps2pdf at 105
gsData = LocalParseArgs(varargin{:});
Error in ==> Final_Combined at 2398
ps2pdf('psfile', 'myfile.ps', 'pdffile', pfilename, 'gspapersize', 'a4')
I understand this date - 09/07/2012 23:22:01 - might not be in the correct format but it doesn't work even for text from an array
Thanks
Walter Roberson
Walter Roberson el 31 de Jul. de 2012
How do you insert raw(3) ? The fact that raw(3) shows quotation marks on output tells us that raw is a cell array, and the third string in it would be accessed by raw{3} rather than raw(3) .
Aadil
Aadil el 31 de Jul. de 2012
Great! That worked thanks.
My next dilemna is converting the date into a filename friendly format, but I'll ask that in a seperate question

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 30 de Jul. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by