how can I copy multiple Matlab.fig files, each with multiple subplots, into a single plot

I am trying to write a script to programmatically open multiple FIG files (each of which has a single plot consisting of 3 subplots) and then place then on a single plot, and then save that as a FIG file. I have followed an example posted in this site, modified with my file names. What happens is that only the last subplot from each FIG file is placed on the new figure (with handle h3). How do I get all the original subplots to appear on the new plot? I have attached the two FIG files.
h1 = openfig('ROC_whole_b1','reuse')
ax1 = gca;
h2 = openfig('ROC_whole_b2','reuse')
ax2 = gca;
h3 = figure;
s1 = subplot(1,2,1)
s2 = subplot(1,2,2)
fig1 = get(ax1,'children');
fig2 = get(ax2,'children');
copyobj(fig1,s1);
copyobj(fig2,s2);

2 comentarios

Do the figures contain any uicontrol or uipanel? Do all the figures use the same colormap, or alternately are all objects in the figure colored by RGB ?
Walter, see my "answer" and "comment" to Amit. No ui-anything, and the color pallete is defined anew for each figure based on a parameter.

Iniciar sesión para comentar.

Respuestas (2)

You need to get handle for all the subplots in each figure.
% First open a new figure
hh = figure;
% Open First File
h1 = openfig('ROC_whole_b1','reuse');
axesVal = findobj(gcf,'Type','axes');
handle = get(axesVal,'Children');
figure(hh);
for j = 1:3
s = subplot(3,2,j); % You said 3 subplots in each figure and total 2 figures. Thus 6 section on the figure
copyobj(handle{j},s);
end
You get the point now.

6 comentarios

Sorry, I mis-stated my issue. The two original figures do not have subplots at all - they have multiple axes. Again, I do not know how to do this with multple axes. If you open the figures I attached you will see this. So the final figure I want assuming two of these should have two figures, one from ROC_b1 and one from ROC_b2, side by side. Eventually I will put 6 side-by-side.
I dont think you attached the figure files here.
Sorry again, I placed my comment on your answers in the Answers box. Let me repeat here. I assyume you can grab the files I uploaded from my "answer".
Sorry, I thought I included them in the original post. I have attached two example figures, and the code that produces them (not my own code) apropo of Walter's questions.There are no ui-anything, and the color maps are potentially different for each figure based on the "gran" parameter.
Thanks, -Jeff
Jeff, I have seen the plots and figures attached here. I think it is better to modify the function plot_ROC_main than trying to merge both plots.
The plot_ROC_main is a nicely written function to get the figures the way you have got. However, merging the 2 plots would be more painstaking than simply modifying the function!!
Reading plot_ROC_whole, I believe you have the data to do so. If not, the data can be extracted as well.
Amit,
Yes, I could potentially modify plot_ROC_whole as you say, but I really want something I can use generally in the future with many kinds of figures in mat.fig files. For the present project, I not only need to make a row of ROC plots, but at the end of the row add another type of figure from another script, not the same aspect ratio, and finally a JPEG image in the last column (which I presumably would have to import and change to an image matrix in order to save as a mat.fig file).
It seems that Matlab graphics can handle what I need, if I just knew a bit more about its structures and functions. I think I should be able to pull out all the structures from a mat.fig file and reuse them, instead of writing some gargantuan plotting prograqm that glues together all the many programs used to greate the individual figures.
Can you pass my question on to someone else who might know how to guide me? Thanks, -Jeff
Jeff,
I am a graduate student and I use Matlab significantly. One thing I know is what can be a headache and how I can avoid it. Sometimes writing a script is better than re-engineer something as re-engineering requires more work than simply writing it.
In you case, you have 3 different axes and the person who wrote the plotting file wrote it nicely for a certain purpose. Now you're trying to take that plot and reengineer it to do it. If I was in your shoes, I'll simply study the original script and change it to do anything I want. (I did read the plotting script and it is a simpler fix to me to re-write it to serve my purpose).
As far as passing the question, you can probably repost your issue!

Iniciar sesión para comentar.

Sorry, I thought I included them in the original post. I have attached two example figures, and the code that produces them (not my own code) apropo of Walter's questions.There are no ui-anything, and the color maps are potentially different for each figure based on the "gran" parameter.
Thanks, -Jeff

Categorías

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

Productos

Etiquetas

Preguntada:

el 1 de Feb. de 2014

Comentada:

el 7 de Feb. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by