本文介绍了如何在 Simulink Scope 中以编程方式“打印到图"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Simulink Scope 中,可以选择 Print to Figure.这将打开一个与原始范围具有相同内容的图形.有没有办法以编程方式执行此操作?

Inside a Simulink Scope, it is possible to select Print to Figure. This will open a figure with the same content as the original scope. Is there a way to perform this action programmatically?

另请参阅此帮助页面这个帮助页面此页面.

推荐答案

取决于您想要/需要获得的创意.

Depends a little on how fancy you want/need to get.

如果您真的想使用与 UI 回调完全相同的代码,那么您需要研究如何使用以下目录/包中的回调函数:

If you really want to use exactly the same code as the UI callback then you'll need to investigate how to use the callback functions in the following directory/package:

MATLABROOT\toolbox\shared\spcuilib+matlabshared+scopes\@UnifiedScope

MATLABROOT\toolbox\shared\spcuilib+matlabshared+scopes\@UnifiedScope

特别是,printToFigureCallback.m 是回调调用的代码.(您可以在代码中放置断点并使用调试器单步调试代码以查看其工作原理.)

In particular, printToFigureCallback.m is the code called by the callback. (You can put a breakpoint in the code and use the debugger to step through the code to see how it works.)

看起来像下面这样的东西应该可以工作,但事实并非如此,因此您需要进行一些试验和错误调查才能使其工作.

It looks as if something like the following should work, but it doesn't, so you'll need to do some trial and error investigation to make it work.

% Get the name of the Scope of interest
scopeName = get_param(gcb,'Name');
% Find the Scope (which is really just a figure window)
hs = findall(0,'Name',scopeName);
% Print to a figure.
printToFigureCallback(h.UserData)

或者,一个更简单但可能不太令人满意的解决方案是执行以下操作:

Alternatively, an easier, although possibly less satisfying solution, would be to do the following:

% Get the name of the Scope of interest
scopeName = get_param(gcb,'Name');
% Find the Scope (which is really just a figure window)
hs = findall(0,'Name',scopeName);
% Create a new target figure
hf = figure('Position',get(hs,'Position'));
% Get the handle to the panel containing the plots
hp = findobj(hs.UserData.Parent,'Tag','VisualizationPanel');
% Copy the panel to the new figure
copyobj(hp,hf)

根据您的要求,您可能需要使用一些单元来确保调整图形大小正确.

Depending on your requirements you may then have to play around with some of the Units to ensure that resizing the figure does the right thing.

这篇关于如何在 Simulink Scope 中以编程方式“打印到图"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 05:03