Take the 2-minute tour ×

If you want to copy a plot through the property structure you need to filter out the read only properties (such as Annotation, BeingDeleted, Parent, Type). Is there a way to get a list of read only properties for the object?

The question arose from a related question

How can I plot from a plot handler?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

I started to muck around with the previous question, trying to dynamically find out which fields were settable.

I didn't quite get it to work but I could get hold of (most of) the read only properties by using the difference between the return values of set(h) and get(h).

The only property that doesn't show up here is the Parent-property which is settable but is not supposed to be changed in the previous question.

Here is how I got the non-settable properties:

h = plot(1:0.2:10);

close all
h2 = plot(0);
settableHandles = set(h2);
settableNames = fieldnames(settableHandles);
allHandles = get(h2);
allNames = fieldnames(allHandles);

nonSettableHandles = rmfield(allHandles,settableNames);
nonSettableNames = fieldnames(nonSettableHandles)

This produces a cell of nonSettableNames:

nonSettableNames = 

share|improve this answer
I guess you can reduce everything to a one liner: fieldnames(rmfield(get(h), fieldnames(set(h)))). Pretty clever, +1. –  Eitan T Dec 10 '12 at 15:31
@EitanT +1 for the one liner! –  user1884905 Dec 10 '12 at 15:34
+1 - I never even noticed that I can get a return value from set! –  Jonas Dec 10 '12 at 15:53

why not use something like

    %// [set property]

catch ME
    if ~isempty( regexp(ME.error, 'read only') )

        %// [handle other error]


share|improve this answer
Nice - are the try/catch blocks expensive in Matlab? –  ccook Dec 10 '12 at 13:40
copyobj has been discussed, but it uses the plot handler directly, not the plot properties :) –  ccook Dec 10 '12 at 13:41
Well, they can be, especially when used in a loop; the ME part is a call to the MException class, which is non-builtin, so any loop will not be accelerated by JIT. But this will be non-applicable when you're using external calls anyway. Besides -- I think it's not likely that your try...catch will really be very expensive compared to all the rest. –  Rody Oldenhuis Dec 10 '12 at 13:44
@ccook: compared to how expensive plotting is, try/catch won't be felt at all. –  Jonas Dec 10 '12 at 13:44
Perspective does help :) TY –  ccook Dec 10 '12 at 13:46

Your Answer


