Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone figure in Matlab - with properties and data

Tags:

matlab

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 display a set of data ( it is graph embedded in a 3d-domain ). Each of these figures is ought furthermore to display a set of particles within that 3d-domain.

So i would like to create the first figure, then make several copies of it, and put in the data sets. However, I do not know, how I can create clones of a figure in Matlab in a simple way.

Do you know, how I can clone figures?

The online documentation didn't help. Thank you very much!

like image 787
shuhalo Avatar asked Sep 09 '10 15:09

shuhalo


People also ask

How do you duplicate a figure in Matlab?

Copy the figure to your system clipboard by clicking Edit > Copy Figure. Paste the copied figure into other applications, typically by right-clicking. By default, MATLAB® converts the background color of the copied figure to white.

How do I save a figure property in Matlab?

The best method for storing a figure's properties, then resetting them at a later time, is to use the SAVEAS function to save the figure as a FIG-file.


2 Answers

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

peaks;
f2=copyobj(gcf,0);
like image 106
Doresoom Avatar answered Oct 04 '22 05:10

Doresoom


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));
like image 29
gnovice Avatar answered Oct 04 '22 05:10

gnovice