File Exchange

image thumbnail


version 2.0.0 (2.08 KB) by Farhad Sedaghati
This code gets different single fig files and plot all of them together inside a new figure.


Updated 26 Mar 2020

View License

This code is used once there are several saved fig files and the goal is to open all of them together in a new figure as different subplots. The order of subplots is based on the order in which figures are opened. It should be noted that all selected fig files must be single figures (no subplots) and defined in the 2-D space
The video (Help_Video.mp4) showing how to use the code is included in the file.

Cite As

Farhad Sedaghati (2020). SubPlot (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (36)

Eryn Kwon

thanks for the code. just one weird thing - when I use multiselect, the first figure is repeated twice. when I choose the figures individually, this code works well. (e.g. if I chose 4 figures individually, it displays [1 2 3 4] but if I used multiselect, it does [1 1 2 3] )

Vic Titova

Cool function. Sadly for me, messes up my legend and mixes up original order of lines in my plots.

Thank you everyone for your comments, the code has been updated to include the multiselect option, and get the legend, x and y limit, scale, tick, and ticklabels

Homa Bayat

متشکر دوست عزیز عالی بود

It can be edited by the selection of 'Multiselect','on' in "uigetfile" in order to select more than fig file eachtime.

Error using subplot
Too many input arguments.

Error in subplot (line 64)
s(i) = subplot(ceil(N/K),K,i);
Please help me out

Thanks, it was really useful, although it could be even better if you could select more than 1 figure each time, you would just need to add some additional lines in a for loop and change the options in the multiselection file, and the position of N in the code, the following modifications worked for me (maintaining all the other parts of the code, just changing the while loop):

while strcmpi(answer,'y')
% Get the path and filename of the desired fig file
while isequal(filename,0)
if run==2
error('please choose your fig file');
disp('Select the desired fig file which you want to insert in the subplot: ');
[filename,pathname]=uigetfile('MultiSelect', 'on',{'*.fig';'*.FIG'},'Select the .fig file you want to insert in the subplot');
clear FN
for figureIndex = 1:size(filename,2)
FN=[pathname filename{1,figureIndex}];
% open figure
h(N) = openfig(FN,'new');
% get handle to axes of figure
answer=input('Do you have more .fig files to read? \n','s');

Jorge Rivé


I really like the idea of this but there seem to be no prompts after inserting the first figure. Perhaps a bug?

Thanks, great work. Is it possible to save same axis properties for all of subplots?
Coz I am using 'Interpreter' 'Latex' for the axis name and after using the code it gives me default style of the axis.

Work as intended!


Attempt to execute SCRIPT subplot as a function:
E:\conference work\drought_indices\figure for paper\subplot.m

Error in subplot (line 37)
s(i) = subplot(ceil(N/K),K,i);

Xai Lao

May you modify this code such that instead of having to pick a figure at a time, the user can provide the directory containing all the figures to be put in a subplot and the function will go grab these and plot them?

Manoj Babu

Brian James

Can you provide the link to the help video please.

Is it possible to get the axis limits from the figures (similar to the way you got the titles and axis labels)?

"tried to use this code but inverts the images in the subplot. What is the cause there? "

Having the same problem and how to put only one xax label and yax label instead of many labels for each figure.

I tried to use this code but inverts the images in the subplot. What is the cause there?

Grind and legend would be very nice features


Jeremy R.

Perhaps also interesting to include the grids and legends of the figures.

Tysha Maffy

Thanks Dave for reporting the bug.
You were right. I fixed it and updated the code.

Dave Si

Thanks, helpful code. But, there is a bug when you have figures with overlaid data, like a figure as plot(x,y,t,z).

putting existing figures into new fig as subplots

I have included x and y labels and titles inside the code. You can again download it.


Thank you for this code.
Any ideas about how to copy title and axis labels?



The objective is to include the multiselect option, and get the legend, x and y limit, scale, tick, and ticklabels

Reported bug has been fixed.

Getting X and Y labels and titles of figures for subplots

The number of rows for subplots

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux