How to tell legends from axes in Matlab?

前端 未结 3 807
有刺的猬
有刺的猬 2021-02-09 21:06

The following stackoverflow qestion:

Matlab: How to obtain all the axes handles in a figure handle?

identifies how to get handles to all of the axes from a figur

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-09 21:57

    Just slightly modifying the code of my answer at the stackoverflow question you mentioned:

    axesHandles = get(fig, 'Children');
    classHandles = handle(axesHandles);
    count = length(axesHandles);
    isLegend = false(1, count);
    for i = 1:count
        isLegend(i) = strcmp(class(classHandles(i)), 'scribe.legend') == 1;
    end
    legendHandles = axesHandles(isLegend);
    

    Unfortunately, this solution depends on implementation details.

提交回复
热议问题