如何加快matlab的“打印”速度功能

发布于 2024-11-26 08:35:42 字数 545 浏览 1 评论 0原文

我在 matlab 中编写了一个相当大的数据采集程序,它以相当严格的时序安排接收输入数据,并在 GUI 上实时绘制它。我的问题是,我需要一种方法让程序用户通过网络查看 GUI 以远程监控他们的数据。我的解决方案是每 5 秒左右拍摄一次 GUI 图形的快照,并将该图像托管在 Web 服务器上。

然而,这会导致两个不可接受的问题:

  1. 打印功能太慢了——每次保存大约需要 3-4 秒,并且在每次调用“打印”后,程序随后会落后于其他例程。

  2. 由于某种原因,打印功能会导致 GUI 暂时变形,从而更改某些组件的位置并重复其他组件。它只持续一秒钟左右,但仍然使我的解决方案不切实际。

有办法解决这两个问题吗?

编辑:*** 对于任何感兴趣的人,我发现的最佳解决方案是使用名为 Minicap

I've written a fairly large data acquisition program in matlab that receives input data on a pretty tight timing schedule and plots it in real-time on the GUI. My problem is that i need a way for users of the program to view the GUI over the web to monitor their data remotely. My solution was to take a snap shot of the GUI figure every 5 seconds or so and host that image on a web server.

However this leads to two unacceptable problems:

  1. The print function is simply too slow-- it takes ~3-4 seconds for each save and the program subsequently falls behind in it's other routines after each call to 'print'.

  2. For some reason the print function causes the GUI to be temporarily distorted, changing the location of some components and duplicating others. It lasts for just a second or so, but it still makes my solution impractical.

Is there a way to solve either of these issues?

EDIT:*** To anyone interested, the best solution i found was to use an external toolkit called Minicap.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

朕就是辣么酷 2024-12-03 08:35:42

文件格式有很大差异。这是一个示例散点图

n = 1e4;
hfig = figure;
hax = plot(1:n, rand(1, n), '+');

......以及保存为不同格式的一些时间。

tic; print(hfig, 'test.bmp', '-dbmp'); toc      %4.1s
tic; print(hfig, 'test.bmp', '-dbmp256'); toc   %2.0s
tic; print(hfig, 'test.png', '-dpng'); toc      %1.9s
tic; print(hfig, 'test.tiff', '-dtiff'); toc    %0.45s
tic; print(hfig, 'test.jpg', '-djpeg'); toc     %0.44s
tic; print(hfig, 'test.wmf', '-dmeta'); toc     %0.42s

tiffjpegwmf 首先联合使用,尽管 tiff 文件很大,jpeg 质量很差,如果您不打开,wmf 也会出现问题Windows 平台。


对于光栅格式,分辨率也会影响时序。

tic; print(hfig, 'test600.png', '-dpng', '-r600'); toc   %4.2s
tic; print(hfig, 'test72.png', '-dpng', '-r72'); toc     %0.31s

加快打印速度的另一件事是删除不需要的绘图部分。透明度是计算密集型的,图例也是如此。对数据进行采样而不是全部绘制出来也可以节省时间。

The file format makes a big difference. Here's a sample scatterplot

n = 1e4;
hfig = figure;
hax = plot(1:n, rand(1, n), '+');

...and some timings for saving to different formats.

tic; print(hfig, 'test.bmp', '-dbmp'); toc      %4.1s
tic; print(hfig, 'test.bmp', '-dbmp256'); toc   %2.0s
tic; print(hfig, 'test.png', '-dpng'); toc      %1.9s
tic; print(hfig, 'test.tiff', '-dtiff'); toc    %0.45s
tic; print(hfig, 'test.jpg', '-djpeg'); toc     %0.44s
tic; print(hfig, 'test.wmf', '-dmeta'); toc     %0.42s

tiff, jpeg and wmf were joint first, though tiff files are huge, jpeg quality is lousy and wmf has problems if you aren't on a Windows platform.


For raster formats, the resolution also affects the timing.

tic; print(hfig, 'test600.png', '-dpng', '-r600'); toc   %4.2s
tic; print(hfig, 'test72.png', '-dpng', '-r72'); toc     %0.31s

Another thing to speed up printing is to remove bits of your plot that you don't need. Transparency is computationally instensive, so are legends. Sampling your data rather than plotting it all will save time too.

野の 2024-12-03 08:35:42

对于将来遇到此问题的任何人,我为 Windows 平台找到的解决方案是一个名为 Minicap,允许用户使用系统命令轻松捕获和保存屏幕截图。

我们需要拥有图形的底层 Windows 句柄,可以使用由超级用户 Yair M. Altman 编写的名为 gethwnd() 的公共可用 matlab 函数来访问该句柄。

然后,您可以快速、高分辨率地截取图形并将其保存到磁盘,如下所示:

winHandle = gethwnd(matlabFigHandle);
cmndstr = sprintf('%s','MiniCap.exe -save ','"',snapShotFileNamePath,'"',...
    ' -compress 9', ' -capturehwnd ', num2str(winHandle),' -exit');
system(cmndstr);

For anyone struggling with this in the future the solution I landed on for Windows platforms is a little program called Minicap that allows one to easily capture and save screenshots with system commands.

One needs to have the underlying Windows handle of the figure, which can be accessed using the publicly available matlab function called gethwnd() written by superuser Yair M. Altman.

You can then take a very fast, high resolution screenshot of a figure and save it to disk with something like the following:

winHandle = gethwnd(matlabFigHandle);
cmndstr = sprintf('%s','MiniCap.exe -save ','"',snapShotFileNamePath,'"',...
    ' -compress 9', ' -capturehwnd ', num2str(winHandle),' -exit');
system(cmndstr);
帅气尐潴 2024-12-03 08:35:42

您的解决方案必须是纯 Matlab 吗?使用平台工具包拍摄包含 GUI 的窗口的快照,并将其写入磁盘。这非常快,而且由于它将在一个单独的线程中,应该可以处理您的线程问题。

Does your solution have to be pure Matlab? Use a platform toolkit to take a snapshot of the window holding the GUI, and write that to disk. That's extremely fast, and since it will be in a separate thread should handle your threading issues.

一抹淡然 2024-12-03 08:35:42

您可能不应该一直捕获,而应该仅捕获实际通过网络发出请求时的捕获。即使这样,也不要捕获每个请求,而仅当最后一个快照早于 5 秒时才捕获。这应该对提高性能大有帮助。

You should probably not capture all the time but only when a request was actually made over the web. Even then, do not capture for each request but only if the last snapshot is older than 5 seconds. That should go a long way towards helping performance.

诗化ㄋ丶相逢 2024-12-03 08:35:42

您可以将图形 saveas() 保存为 .fig 文件(应该相当快),让 MATLAB 实例进行计算,然后使用不同的 MATLAB 实例(可能在另一台计算机)将其打印为所需的格式。这样您就可以避免其他例程的延迟,并且打印引起的失真不会发生在您的“主”MATLAB 实例上。

请注意,print 是一个 .m 文件,您可以查看该文件以查看是否有针对您的特定情况可以丢弃的内容。例如,它调用 private/prepare.m 我认为这会导致您所说的扭曲/位置变化......也许您可以尝试一下?

更新:数据必须通过网络界面吗?如果用户群足够小,也许您可​​以尝试教他们使用远程桌面软件(例如 VNC、Teamviewer 或 Windows 内置的终端服务器)来远程查看数据?

You could saveas() your figure as a .fig file (which should be rather fast) with the MATLAB instance doing the calculations, then use a different MATLAB instance (possibly on a different computer) to print it to the needed format. This way you avoid delays for your other routines, and the distorions caused by print don't happen on your "main" MATLAB instance.

Note that print is an .m file that you can look into to see if there is anything you can throw out for your particular case. For example, it calls private/prepare.m which I think causes the distortions / position changes you talk about... maybe you could play around with this?

Update: Does the data have to go through a web interface? If the userbase was small enough, maybe you could try to get away with teaching them to use a remote desktop software, such as VNC, Teamviewer or the Terminal Server stuff built into Windows to remotely view their data?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文