Variable string as filename using export_fig

I want to save multiple figures in one pdf using export_fig. The name for the pdf-file depends on the file to be analysed, e.g. if I have a file called Erica.csv, the output pdf-file should be called Erica.pdf.
I allready have a code for extracting the correct string:
figname=(strcat(all_files(file_no).name(1:end-4),'.pdf'));
When I wanted to use export_fig, I tried:
export_fig figname -transparent -append
However, this creates a pdf-file called 'figname.pdf', while I want it to be called for example 'Erica.pdf'
I also tried:
export_fig (figname -transparent -append) or export_fig (figname) -transparent -append
But in this case an error occurs:
Undefined function or variable 'transparent'.
How can I solve this?
Thanks!
Vincent

 Akzeptierte Antwort

Stephen23
Stephen23 am 16 Jul. 2015
Bearbeitet: Stephen23 am 16 Jul. 2015

1 Stimme

You need to learn about the difference between function syntax and command syntax:
When you are creating strings, such as the optional arguments to a function call, then you need to tell MATLAB that they are strings by placing them inside single quotes, otherwise it will think they are functions or variables. So your code should be something like this:
export_fig(figname,'-transparent','-append')
Of course if you had actually read the export_fig documentation then you would have found these very clear examples listed under the heading "Variable file names":
"Here's an example of this:"
for a = 1:5
plot(rand(5, 2));
export_fig(sprintf('plot%d.png', a));
end
"When using the functional form like this, be sure to put string variables in quotes:"
export_fig(sprintf('plot%d', a), '-a1', '-pdf', '-png');

Weitere Antworten (0)

Kategorien

Tags

Gefragt:

am 16 Jul. 2015

Bearbeitet:

am 16 Jul. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by