Clone figure in Matlab - with properties and data

后端 未结 3 2145
粉色の甜心
粉色の甜心 2021-02-20 08:53

I write a script in matlab, which produces figures out a set of data.

The figures are supposed to rather similar with respect to formating, and each of them is ought to

相关标签:
3条回答
  • 2021-02-20 09:38

    A convenient way to generate a function that sets all the parameters such that the figure (as in @gnovice's post) will look just right is to create the first figure with all the data (including the 3D points) and all the formatting, and then choose from the FILE-menu the command GENERATE M-FILE... (have a look at the tutorial linked here).

    This creates a function that you can save on the Matlab path, and which you can later call with new input to create an exact clone of the first figure with new data.

    0 讨论(0)
  • 2021-02-20 09:43

    You can put the code you use to generate your base figure into a function, then call that function multiple times to create multiple copies of your base figure. You will want to return the graphics handles for those figures (and probably their axes) as outputs from the function in order to modify each with a different set of plotted data. For example, this function makes a 500-by-500 pixel figure positioned 100 pixels in from the left and bottom of the screen with a red background and one axes with a given set of input data plotted on it:

    function [hFigure,hAxes] = make_my_figure(dataX,dataY)
      hFigure = figure('Color','r','Position',[100 100 500 500]);  %# Make figure
      hAxes = axes('Parent',hFigure);                              %# Make axes
      plot(hAxes,dataX,dataY);  %# Plot the data
      hold(hAxes,'on');         %# Subsequent plots won't replace existing data
    end
    

    With the above function saved to an m-file on your MATLAB path, you can make three copies of the figure by calling make_my_figure three times with the same set of input data and storing the handles it returns in separate variables:

    x = rand(1,100);
    y = rand(1,100);
    [hFigure1,hAxes1] = make_my_figure(x,y);
    [hFigure2,hAxes2] = make_my_figure(x,y);
    [hFigure3,hAxes3] = make_my_figure(x,y);
    

    And you can add data to the axes of the second figure like so:

    plot(hAxes2,rand(1,100),rand(1,100));
    
    0 讨论(0)
  • 2021-02-20 09:55

    MATLAB's built-in function copyobj should also work. Here's an example:

    peaks;
    f2=copyobj(gcf,0);
    
    0 讨论(0)
提交回复
热议问题