我有图的处理程序,或图形的手柄例:
h = plot([1:0.2:10])
xx=get(h)
xx =
DisplayName: ''
Annotation: [1x1 handle]
Color: [0 0 1]
LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerEdgeColor: 'auto'
MarkerFaceColor: 'none'
XData: [1x46 double]
YData: [1x46 double]
ZData: [1x0 double]
BeingDeleted: 'off'
ButtonDownFcn: []
Children: [0x1 double]
Clipping: 'on'
CreateFcn: []
DeleteFcn: []
BusyAction: 'queue'
HandleVisibility: 'on'
HitTest: 'on'
Interruptible: 'on'
Selected: 'off'
SelectionHighlight: 'on'
Tag: ''
Type: 'line'
UIContextMenu: []
UserData: []
Visible: 'on'
Parent: 173.0107
XDataMode: 'auto'
XDataSource: ''
YDataSource: ''
ZDataSource: ''
此处理程序包含所有绘图信息,如何再次绘制?这是一个简单的plot
示例,但它也应该适用于slice
。
正确理解您的问题,您想使用结构xx
重现情节。ccook 提供的答案是正确的,但这里有一个更短的方法来实现你想要的:
figure
h2 = plot(0);
ro_props = [fieldnames(rmfield(xx, fieldnames(set(h2)))); 'Parent'];
xx = rmfield(xx, ro_props);
set(h2, xx)
最后一个 set
命令使用结构xx
来设置所有值并重现绘图。请注意,在调用 set
之前,将从xx
中删除只读属性ro_props
。
编辑:修改答案以根据此建议自动检测只读属性。
您可以使用 copyobj
h = plot([1:0.2:10])
xx=get(h)
figure
copyobj(h,gca)
这会将情节复制到新图形上
请参阅:http://www.mathworks.com/help/matlab/ref/copyobj.html
更新
我认为你不能直接从结构 xx 创建,尝试这样做:
h = plot([1:0.2:10])
xx=get(h)
h2 = plot(0,0)
set(h2,xx)
引发错误
Error using graph2d.lineseries/set
Changing the 'Annotation' property of line is not allowed.
您需要手动设置一些属性值,如下所示:
h = plot([1:0.2:10])
xx=get(h)
figure
h2 = plot(0.0)
names = fieldnames(xx);
fieldCount = size(names,1);
protectedNames = {'DisplayName' 'Annotation' 'BeingDeleted' 'Type' 'Parent'}
for i = 1:fieldCount
name = names{i};
if ( ismember(protectedNames, name) == false )
set(h2, name, getfield(xx,name))
end
end
yy=get(h2)
是否有更简单的方法,但是XData和YData中有x,y值。
做:
figure
plot(get(h,'XData'),get(h,'YData'))