How can I plot from a handler?

I have a plot handler or figure descriptor 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 display again? This is a simple example with plot , but it should also work with slice .

+5
source share
3 answers

If I understand your question correctly, you want to reproduce the plot using struct xx . Ccook's answer is presented on the right track, but here is 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 values โ€‹โ€‹and play your plot. Note that the ro_props only ro_props properties are removed from xx before calling set .

EDIT: A modified answer for automatically detecting read-only properties in accordance with this sentence .

+6
source

You can use copyobj

 h = plot([1:0.2:10]) xx=get(h) figure copyobj(h,gca) 

This duplicates the graph to a new digit.

See: http://www.mathworks.com/help/matlab/ref/copyobj.html

UPDATE

I don't think you can create directly from the xx structure by trying to do this:

 h = plot([1:0.2:10]) xx=get(h) h2 = plot(0,0) set(h2,xx) 

Gives an error message

 Error using graph2d.lineseries/set Changing the 'Annotation' property of line is not allowed. 

You will need to manually set some property values:

 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) 
+5
source

I don't know if there is an easier way, but you have the x, y values โ€‹โ€‹inside XData and YData.

make:

 figure plot(get(h,'XData'),get(h,'YData')) 
0
source

All Articles