

For example, create two plots in a 2-by-1. Then call a plotting function to plot into the axes. So my problem was that I couldn't get the second figure (fig2)into the combined figure. figures into one single figure (as 2 subplots), and got a problem - I got two copied of the first figure side by side.
#Matlab combine figures into subplot code
After creating a layout, call the nexttile function to place an axes object into the layout. I just tried using Martin's code to combine two existing matlab. Each tile can contain an axes for displaying a plot. We can get the GridSpec from the axes and then remove the covered axes and fill the gap with a new bigger axes. This function creates a tiled chart layout containing an invisible grid of tiles over the entire figure. I have an answer here as an example: h1 = figure(1)Īmro's solution works greatly, but with boxplots you have to reset the Xtick and Xtick labels, otherwise, for some reason, they will not be resized according to the the subplot. Combining two subplots using subplots and GridSpec Sometimes we want to combine two subplots in an axes layout created with subplots. Assign the Legend object to the variable lgd. Assign the Axes objects to the variables ax1 and ax2. test1.fig and test2. Create two plots in two different figures.

Save your subplot as a FIG file so you have complete control over it later (as opposed to a JPG).Ĭhoose a tiling pattern and then use subplot to display multiple figures in one. Convert Axes in Separate Figures to Subplots Combine axes that exist in separate figures in a single figure with subplots. This was adapted from this newsgroup discussion HAx = get(hFigFile, 'Child') %# hAx = gca %# move/copy axis from old fig to new fig All graphs are scatterplots with fit functions. The axis limits and labels should not be altered. fig files inside the new figureįileNames = %# saved *.fig file names is there a way to combine two already saved Matlab figures both with a 1x3 grid of subplots, into one new figure with a 2x3 grid of subplots. Pos = get(h, 'Position') %# record their positions For i=1:2, h(i) = subplot(2,1,i) end %# create subplots
