How to merge two figure files into a single file

后端 未结 3 1511
眼角桃花
眼角桃花 2020-12-15 01:40

This should be a problem with a trivial solution, but still I wasn\'t able to find one.

Say that I have 2 matlab figures fig1.fig, fig2.fig

3条回答
  •  误落风尘
    2020-12-15 02:01

    Its not clear if you want to extract data from the figures and compare the data, or if you want to combine the plots from two figures into a single figure.

    Here is how you combine two figures into one (if thats what you want to do)..

    First load the figures:

    fig1 = open('FigureFile1.fig');
    fig2 = open('FigureFile2.fig');
    

    Get the axes objects from the figures

    ax1 = get(fig1, 'Children');
    ax2 = get(fig2, 'Children');
    

    Now copy the hangle graphics objects from ax2 to ax1. The loop isn't neccesary if your figures only have a single axes

    for i = 1 : numel(ax2) 
       ax2Children = get(ax2(i),'Children');
       copyobj(ax2Children, ax1(i));
    end
    

    Note This example assumes that your figures have the same nubmer of axes and that you want to copy objects from the first axes in the second figure to the first axes on the first figure. Its up to you to figure out the proper indexing if the axes indices aren't lined up.

提交回复
热议问题