问题
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?
See also this help page, this help page and this page.
回答1:
Depends a little on how fancy you want/need to get.
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
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.
来源:https://stackoverflow.com/questions/37791364/how-to-programmatically-print-to-figure-in-a-simulink-scope