Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a list of read only property names for a plot

Tags:

matlab

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?

like image 334
ccook Avatar asked Dec 10 '12 13:12

ccook


2 Answers

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);
xx=get(h)

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 = 

    'Annotation'
    'BeingDeleted'
    'Type'
like image 62
user1884905 Avatar answered Nov 20 '22 00:11

user1884905


why not use something like

try
    %// [set property]

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

    else
        %// [handle other error]

    end

end 
like image 41
Rody Oldenhuis Avatar answered Nov 20 '22 00:11

Rody Oldenhuis