Get a list of read only property names for a plot

后端 未结 2 633
礼貌的吻别
礼貌的吻别 2021-01-05 15:07

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 t

相关标签:
2条回答
  • 2021-01-05 15:57

    why not use something like

    try
        %// [set property]
    
    catch ME
        if ~isempty( regexp(ME.error, 'read only') )
            continue;
    
        else
            %// [handle other error]
    
        end
    
    end 
    
    0 讨论(0)
  • 2021-01-05 15:58

    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'
    
    0 讨论(0)
提交回复
热议问题