【问题标题】:Matlab - plot directly to .ps fileMatlab - 直接绘制到 .ps 文件
【发布时间】:2014-10-16 14:03:36
【问题描述】:

目前我正在尝试做类似的事情:

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 ) );

因此,以上将在屏幕上生成 .fig 输出。模块 createPDF 调用将打开的图形转换为 .ps 文件并将它们更改为 PDF。当我在我的 PC 上本地运行它时,我看到所有数字都弹出,然后它们被转换为 .PS 并最终转换为 PDF

但是,我正在服务器上将其作为没有屏幕的批处理过程运行,因此我认为也不会有 .fig 输出。如何将这些图直接发送到 .PS 文件。上面的代码在for循环中运行,生成了45个不同的数字。

谢谢

【问题讨论】:

    标签: matlab


    【解决方案1】:

    打印功能就是你要找的!

    print('-dpsc2','-append','YourPSFile'); %// The '-append' is used to create a single file in the loop instead of multiple files.
    

    完整代码:

    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
    

    这是 pdf 的屏幕截图:

    【讨论】:

    • 谢谢 Benoit_11 今天我从你的代码中学到了一些东西。您能否添加一个 for 循环,因为我现在正在使用您的代码创建 45 个 PDF。我只想要 1 个 PDF 输出。如果可能的话,添加用于将 PS 转换为 PDF 的命令。
    • 是的,我编辑了答案;您只需要在 print 调用中添加“附加”输入即可。
    • 你用什么命令把PS转PDF。我正在使用我的公司创造的东西,而不是它的忠实粉丝。
    • 哦,我实际上用 Acrobat 打开了 ps 文件,它运行良好。对于 Matlab 脚本,您可以从文件交换中检查此提交:mathworks.com/matlabcentral/fileexchange/19516-ps2pdf
    • 谢谢 Benoit_11。我会让你知道它是否适用于我的夜间进程设置,我认为它是一个服务器并运行某些版本的 Linux。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多