figure to pdf but without the displaying it in the "figure-window"?
10 views (last 30 days)
Show older comments
Hi
I have this code where I want to make a pdf from some plotted data. But I dont want the display "figure window" to show. I just want it to only save the pdf and now show the plot. Right now I'm using: close(handles.figure1) to remove it. But I would like to save the computation time of presenting the plot, just to close it right after because im only interested in saving it in a pdf file.
Here is my code:
Create figure
handles.figure1 = figure('PaperOrientation','landscape','PaperType','A3',...
'PaperSize',[41.980612 29.703776],...
'Color',[1 1 1]);
% Create axes
axes1 = axes('Parent',handles.figure1,...
'Position',[0.0697916666666667 0.11 0.916145833333332 0.815]);
hold(axes1,'on');
% Create area
area(slag,test,'FaceColor','r','FaceAlpha',.3,'EdgeAlpha',.3)
% Create xlabel
xlabel('Antal Slag [-]');
% Create title
title('Rammekriterie');
% Create ylabel
ylabel('Fald Højde [m]');
% Uncomment the following line to preserve the X-limits of the axes
xlim(axes1,[4 80]);
%ylim(axes1,[0 1.05]);
box(axes1,'on');
% Set the remaining axes properties
set(axes1,'FontSize',20,'XGrid','on','XMinorGrid','on','XMinorTick','on',...
'XTick',...
4:2:80,...
'YGrid','on','YMinorGrid','on','YMinorTick','on','YTick',...
0:0.05:2.5,...
'ZMinorTick','on');
hA = gca;
hA.XAxis.MinorTickValues = 5:2:79;
% Create textbox
annotation(handles.figure1,'textbox',...
[0.73 0.697616060225847 0.3 0.198243412797992],...
'String',{['Dimensioner: ' num2str(Dim*100) 'x' num2str(Dim*100) ' cm'],['Pæle længde:' num2str(L) ' m'],['Faldlod: ' num2str(vaegt) ' kN'],['Bæreevne (Rcd): ' num2str(Rcd) ' kN']},...
'LineWidth',2,...
'HorizontalAlignment','left',...
'FontWeight','bold',...
'FontSize',22,...
'FitBoxToText','off',...
'EdgeColor','none');
[FileName,PathName] = uiputfile('test.pdf','Save Print');
print(handles.figure1, '-fillpage', '-dpdf', fullfile(PathName, FileName))
close(handles.figure1)
So to clarify my question, how do I make a pdf without having the plot appear in the "figure-window"?
Is there a workaround other than:
f = figure('visible', 'off');
0 Comments
Accepted Answer
ANKUR KUMAR
on 5 Dec 2017
Use print or saveas function to save a plot/figure. To close your figure window automatically after saving the plot in pdf.jpeg, then just write cab at the end of the program. It automatically closes all figure windows.
You can get cab function from https://in.mathworks.com/matlabcentral/fileexchange/24420-close-all-figures-except-those-listed
Just copy this function and paste it in your home directory. After this, whenever you want to close all figure window, just write cab
0 Comments
More Answers (0)
See Also
Categories
Find more on Interactive Control and Callbacks 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!