これを行う方法はありますか?
saveas(saveas(1, filename, 'pdf');
)を使用して1つの図をPDFファイルに保存する方法を知っていますが、複数を追加することは可能ですか?つまり、(saveas(1,2,3) filename, 'pdf'));
。
ありがとう
これを行う方法はありますか?
saveas(saveas(1, filename, 'pdf');
)を使用して1つの図をPDFファイルに保存する方法を知っていますが、複数を追加することは可能ですか?つまり、(saveas(1,2,3) filename, 'pdf'));
。
ありがとう
私はそうは思いません-何らかの方法でファイル名をインクリメントする必要があります。私は次のようなものを使用します:
for ii=1:3
saveas(ii,[filename '-' num2str(ii)],'pdf)
end
ちなみに、matlabによって生成されたPDFを原稿の提出に含める際に、何度も困難を繰り返してきました。私の現在の解決策は、epsファイルを作成し、シェルスクリプトで変換することです。
r /
hgsave
狙っている動作はとを使用して取得できることを指摘する価値があると思いましたが、hgload
.figを使用して保存することに満足している場合に限ります。これらの関数のドキュメントは、他の拡張子(.pdfなど)で動作する可能性があるとしばらくの間私を騙しましたが、自分のマシン(Linux Mint v12、Matlab r2012b)で動作する例を取得できませんでした。おそらく他の誰かがもっとうまくやれるかもしれません。.fig拡張子で動作する例は次のとおりです。
%# Create some example data
x = (0:10)';
y1 = (1/10) * x;
y2 = sin(x);
%# Create an array of figures and an array of axes
AllFig(1) = figure('Visible', 'off');
AllFig(2) = figure('Visible', 'off');
AllAxes(1) = axes('Parent', AllFig(1));
AllAxes(2) = axes('Parent', AllFig(2));
%# Plot the data on the appropriate axes
plot(AllAxes(1), y1);
plot(AllAxes(2), y2);
%# Save both figures to .fig in one hit using hgsave
hgsave(AllFig, 'TwoFigsOneFile.fig');
% Clear the workspace
clear
%# Load both figures in one hit using hgload
LoadFig = hgload('TwoFigsOneFile.fig');
%# Display the first figure and second figure
figure(LoadFig(1));
figure(LoadFig(2));
返信が遅れましたが、publishコマンドを使用してpdfに公開できることを付け加えたいと思いました。次のように、plotコマンドを使用してmファイル'myfile.m'を作成します。
plot(x1,y1);
plot(x2,y2);
次に、このファイルを使用して実行します
publish('myfile.m', 'pdf')
これはあなたが望むものを与えるはずです。
publish
他の回答が指摘しているように、MATLABのコマンドを使用することは優れたソリューションです。さまざまな図を組み合わせる方法に関してより詳細な制御を探している場合、別の解決策はpdflatex
、図を1つのPDFにコンパイルするために使用することです。
LaTeX
図を含むコードを生成するPDFLaTeX
以下は、ファイル名をaといくつかの数として取り、それらの図を含むPDFを生成する概念実証です。char
function_handle
function res = save2pdf(name,varargin)
pathToPdflatex = '/Library/TeX/texbin/pdflatex' ;
files = cell(size(varargin)) ;
for ii = 1:numel(varargin)
files{ii} = sprintf('%s_fig%g.pdf',name,ii) ;
print(varargin{ii},'-dpdf','-painters',files{ii}) ;
end
fh = fopen(sprintf('%s.tex',name),'w+') ;
fprintf(fh,'\\documentclass{article}\n') ;
fprintf(fh,'\\usepackage{graphicx}\n') ;
fprintf(fh,'\\begin{document}\n') ;
for ii = 1:numel(files)
fprintf(fh,'\\includegraphics[width=\\textwidth]{%s}\n\\newpage\n',files{ii}) ;
end
fprintf(fh,'\\end{document}\n') ;
fclose(fh) ;
[~,res] = system(sprintf('%s %s.tex',pathToPdflatex,name)) ;
disp(res)
end
例:
n = 1e+5 ;
x0 = cumsum(randn(n,1)) ;
x1 = cumsum(randn(n,1)) ;
f0 = figure() ;
f1 = figure() ;
ax0 = axes('Parent',f0) ;
ax1 = axes('Parent',f1) ;
plot(ax0,x0) ;
plot(ax1,x1) ;
save2pdf('my_figures',f0,f1)
出来上がり:
...
Output written on my_figures.pdf (2 pages, 169718 bytes).
Transcript written on my_figures.log.
すべての図を1つのPDFに保存するためのinbuildコマンドはありません。多くの回避策があります。
図ごとにPDFファイルを作成し、簡単に入手できるソフトウェアを使用してそれらを結合します。
図を単一のPDFに保存できるExport_fig(http://www.mathworks.com/matlabcentral/fileexchange/23629 )というスクリプトがあります。