gpt4 book ai didi

matlab - 在matlab中打印多个图形

转载 作者:太空宇宙 更新时间:2023-11-03 19:47:32 24 4
gpt4 key购买 nike

假设我在我的程序中产生了几个图形。我想给用户一次打印它们的选项。我不想为每一页都显示打印对话框。因此,我只显示一次并且只显示第一个数字。这是我到目前为止提出的解决方案:

figHandles = get(0, 'Children');
for currFig = 1:length(figHandles)
if(currFig == 1)
printdlg(figHandles(currFig)); % Shows the print dialog for the first figure
else
print(figHandles(currFig)); % Does not show the print dialog and uses the latest printer selection
end
end

但问题是,如果用户取消第一个图形的打印,我无法捕捉到它并取消其他打印。我应该如何实现?

最佳答案

好吧,这是一个非常肮脏的技巧,绝对不能保证它适用于所有版本。它在 Matlab 2013a/win 7 上对我有用。

要让 Matlab 返回一个关于它是否执行了打印作业的值,您需要在 print.m 函数中插入一个小 hack。


破解 print.m

  • 找到 print.m 函数。它应该位于 ..\toolbox\matlab\graphics\print.m 周围的 matlab 安装文件夹中。

  • 一旦找到,制作一个备份副本!(这个技巧是次要的,应该不会破坏任何东西,但我们永远不知道)。

  • 打开文件 print.m 并找到 LocalPrint(pj); 行,它应该在 main 函数附近或末尾 (~我的第 240 行)。

  • 将行替换为:

.

pj = LocalPrint(pj); %// Add output to the call to LocalPrint
if (nargout == 1)
varargout{1} = pj ; %// transfer this output to the output of the `print` function
end
  • 保存文件。

完成黑客攻击。现在,每次调用 print 函数时,您都可以得到一个充满信息的返回参数。


应用于您的案例:

首先,请注意在 Windows 机器上,printdlg 函数等同于使用 '-v' 参数调用 print 函数。
所以 printdlg(figHandle)print('-v',figHandle) 完全相同。 ('-v' 代表verbose)。我们将使用它。

print 函数的输出将是一个包含许多字段的结构(我们称它为 pj)。您要检查以了解打印命令是否实际执行的字段是 pj.Return

pj.return == 0 => job cancelled
pj.return == 1 => job sent to printer

所以在你的例子中,在 print.m 上调整之后,它可能看起来像这样:

pj = print('-v',figHandles(1)); %// Shows the print dialog for the first figure
if pj.Return %//if the first figure was actually printed (and not cancelled)
for currFig = 2:length(figHandles)
print(figHandles(currFig)); %// Does not show the print dialog and uses the latest printer selection
end
end

注意:pj 结构包含更多可重用的信息,包括打印作业选项、当前选择的打印机等...

关于matlab - 在matlab中打印多个图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26284443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com