我有绘图的处理程序,或图的示例处理示例:
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: ''
Run Code Online (Sandbox Code Playgroud)
此处理程序包含所有绘图信息,如何再次绘制出来?这是一个简单的例子,plot但它应该也可以使用slice.
如果我正确理解您的问题,您希望使用结构重现绘图xx.提供的答案是在正确的轨道上,但这是实现您想要的更短的方式:
figure
h2 = plot(0);
ro_props = [fieldnames(rmfield(xx, fieldnames(set(h2)))); 'Parent'];
xx = rmfield(xx, ro_props);
set(h2, xx)
Run Code Online (Sandbox Code Playgroud)
最后一个set命令使用struct xx来设置所有值并重现您的绘图.请注意,在调用之前ro_props将删除只读属性.xxset
编辑:根据此建议修改了自动检测只读属性的答案.
你可以使用copyobj
h = plot([1:0.2:10])
xx=get(h)
figure
copyobj(h,gca)
Run Code Online (Sandbox Code Playgroud)
这将图重复到一个新图上
请参阅:http: //www.mathworks.com/help/matlab/ref/copyobj.html
UPDATE
我不认为你可以直接从结构xx创建,试图这样做:
h = plot([1:0.2:10])
xx=get(h)
h2 = plot(0,0)
set(h2,xx)
Run Code Online (Sandbox Code Playgroud)
引发错误
Error using graph2d.lineseries/set
Changing the 'Annotation' property of line is not allowed.
Run Code Online (Sandbox Code Playgroud)
您需要手动设置一些属性值,如下所示:
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)
Run Code Online (Sandbox Code Playgroud)