Combine three or more MATLAB figures

Hello, I am new to MATLAB. I have three MATLAB figures. I want to combine them to compare the data. Can someone help me doing this?

9 comentarios

KALYAN ACHARJYA
KALYAN ACHARJYA el 31 de Ag. de 2019
I am using two different MATLAB windows and running two different codes on them
Can you elaborate more?
Tomer
Tomer el 31 de Ag. de 2019
Editada: Tomer el 31 de Ag. de 2019
I have two different programs and I am running them on two MATLAB windows. Each code creates a figure as the result. I want to combine the figures from these two programs to compare the results of two test cases.
rough93
rough93 el 18 de Sept. de 2019
You would need to combine the codes in this case, unless you developed the code to save the figures and then layered them using the graphic editing abilities of MATLAB, but this would be much more complicated.
prasanth s
prasanth s el 2 de Oct. de 2019
save the figure as fig extension. it can be loaded as a figure in new program.
SS
SS el 4 de Oct. de 2019
Hi. I am not sure if, there is a way to combine multiple fig files. Below is the link for combining two matlab plots. Firstly, I have combined two plots and then combined the third plot with the newly created fig file.
Adam Danz
Adam Danz el 4 de Oct. de 2019
Editada: Adam Danz el 5 de Oct. de 2019
Option 1 is to merely save the data instead of plotting the data. Once you have both datasets, just plot them together on 1 plot.
Option 2 is to use copyobj() to copy all of the children from one axis to another.
[addendum]
Option 3 is the grab the XData and YData from each graphic object and to use those data to produce a new plot.
Tomer
Tomer el 5 de Oct. de 2019
Unfortunately, I can't use these options. I have four matlab figures (4 different cases). I want to combine them and plot them all as a single figure.
Adam Danz
Adam Danz el 5 de Oct. de 2019
Editada: Adam Danz el 6 de Oct. de 2019
Both of those options as well as option #3 (which I just added) do exactly what you're describing. It sounds like you'd rather work with the previously created figures rather than with the code that produced the figures. If that's the case, option 2 and 3 are viable options, unless I'm not understanding the problem.
For option 2, you merely need to copy the line objects from 3 of the 4 figures on to the 4th figure (or copy objects from all 4 figs to a new figure). That can be done manually or programmatically (copyobj).
For option 3, you just need to get the handles to your line objects and then access the XData and YData (and ZData?). Then you can use those data to create a new plot. Note that depending on what you're plotting, you may want to access a different set of data from the handle.
If you need specific help with that, we'll need more info and perhaps a copy of the figure.
Marvin
Marvin el 26 de Feb. de 2024
Hey, maybe you are reading this comment here. I have a kinda same problem i would say. First of all i am kinda new to Matlab. My problem is that i have 2 single Yagi Uda Antennas which i designed with putting data in (see Code) and these both Yagis I would like to combine in one Figure so that i can cross them and get at the End a crossed YagiUda which i can optimize with a Code, maybe you can help me or atleast tell me where i can look up for my Problem.
Best regards.
Code:
figure(2);
Numdirs = 1;
yagidesign_1 = yagiUda;
show(yagidesign_1)
figure(3);
yagidesign_2 = yagiUda;
yagidesign_2.NumDirectors = Numdirs;
yagidesign_2.ReflectorLength = RL;
yagidesign_2.DirectorLength = DL;
yagidesign_2.DirectorSpacing = d_Spaceing_2;
yagidesign_2.ReflectorSpacing = d_Spaceing;
yagidesign_2.Exciter.Length = EL
show(yagidesign_2)

Iniciar sesión para comentar.

 Respuesta aceptada

meghannmarie
meghannmarie el 4 de Oct. de 2019

1 voto

I would save figures then plot them as subplots like this:
%First Figure
h1 = openfig('test1.fig','reuse'); % open figure
ax1 = gca; % get handle to axes of figure
%Second Figure
h2 = openfig('test2.fig','reuse');
ax2 = gca;
h3 = figure; %create new figure
s1 = subplot(1,2,1); %create and get handle to the subplot axes
s2 = subplot(1,2,2);
fig1 = get(ax1,'children'); %get handle to all the children in the figure
fig2 = get(ax2,'children');
copyobj(fig1,s1); %copy children to new parent axes i.e. the subplot axes
copyobj(fig2,s2);

4 comentarios

Tomer
Tomer el 5 de Oct. de 2019
I mean, I want to combine all the four figures as a single figure.
meghannmarie
meghannmarie el 6 de Oct. de 2019
Editada: meghannmarie el 6 de Oct. de 2019
Do you want them on one axis?
fig = figure();
ax = axes(fig);
hold on
h1 = openfig('test1.fig','reuse');
h2 = openfig('test2.fig','reuse');
h3 = openfig('test3.fig','reuse');
copyobj(h1.Children.Children,ax);
copyobj(h2.Children.Children,ax);
copyobj(h3.Children.Children,ax);
close(h1);
close(h2);
close(h3);
Adam Danz
Adam Danz el 6 de Oct. de 2019
Editada: Adam Danz el 6 de Oct. de 2019
@Tomer, meghannmarie 's demo above demonstrates my option #2.
h1 is the figure handle to test1.fig.
h1.Children will list the axes and any other object stored on that figure. If There's just 1 axes and nothing else, you can use this demo code directly. Otherwise you'll need to add an additional step to locate the axis (that's easy - we could help you with that). Then you want to get the children of the axis which will be the handles to any graphic objects stored on the axes. They will then be copied to the new axes.
Tomer
Tomer el 15 de Oct. de 2019
Thanks.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Preguntada:

el 31 de Ag. de 2019

Comentada:

el 26 de Feb. de 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by