I have the handler of the plot, or handle of the figure Example:
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: ''
This handler contains all the plot information, how can I plot out again? This is a simple example with plot
but it is supposed to work with slice
as well.
When you create graphics objects, you can save the handle to the object in a variable. For example: x = 1:10; y = x. ^2; plot(x,y); h = text(5,25,'*(5,25)');
A handle is a floating-point scalar that points to a large list of different properties. Each element of a plot has its own properties, and its own handle.
If I understand your question correctly, you want to reproduce a plot using the struct xx
.
The answer ccook provided is on the right track, but here's a shorter way to achieve what you want:
figure
h2 = plot(0);
ro_props = [fieldnames(rmfield(xx, fieldnames(set(h2)))); 'Parent'];
xx = rmfield(xx, ro_props);
set(h2, xx)
The last set
command uses struct xx
to set all the values and reproduce your plot. Note that the read-only properties ro_props
are removed from xx
before calling set
.
EDIT: modified answer to automatically detect read-only properties according to this suggestion.
You can use copyobj
h = plot([1:0.2:10])
xx=get(h)
figure
copyobj(h,gca)
This duplicates the plot onto a new figure
See: http://www.mathworks.com/help/matlab/ref/copyobj.html
UPDATE
I don't think you can create directly from the structure xx, trying to do so:
h = plot([1:0.2:10])
xx=get(h)
h2 = plot(0,0)
set(h2,xx)
Throws an error
Error using graph2d.lineseries/set
Changing the 'Annotation' property of line is not allowed.
You would need to set some of the property values manually like so:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With