Reputation: 4807
Currently I am trying to do something like:
h = figure( 1 );
subplot( 1, 2, 1);
plot( X, Y );
grid on;
xlabel( 'abc' );
ylabel( 'xyz' );
title( 'Nice' );
legend( 'Awesome' )
handles = findall( 0, 'type', 'figure' );
createPDF( 'outputFileName', numel( handles ) );
So, the above would generate a .fig output on screen. The module createPDF has calls to convert the open figure to .ps file and change them to PDF. When I run this locally on my PC I see all the figures popping up and they are then converted to .PS and ultimately to PDF
However, I am working on running this on the server as a batch process where there is no screen and hence I assume there will be no .fig output either. How do I send these plots straight to the .PS file. The above code runs in for loop and generates 45 different figures.
Thanks
Upvotes: 2
Views: 1810
Reputation: 13945
The print function is what you're looking for!
print('-dpsc2','-append','YourPSFile'); %// The '-append' is used to create a single file in the loop instead of multiple files.
Whole code:
clear
clc
for k = 1:5
X = 1:10;
Y = rand(1,10);
h = figure('Visible','off');
plot( X, Y );
grid on;
xlabel( 'abc' );
ylabel( 'xyz' );
title( 'Nice' );
legend( 'Awesome' )
print('-dpsc2','-append','YourPSFile'); %//Simply replace 'YourPSFile'with the name you want. Easy to implement in a for-loop with sprintf for instance.
end
Here is a screen shot of the pdf:
Upvotes: 3