Solved

Multiple figure in matlab

Posted on 2011-09-08
7
942 Views
Last Modified: 2016-03-02
I created 4 different figures and i load it to a Matlab (4 figures in one page).Is it possible to export this page to png format ? (i need 4 graph per page)
0
Comment
Question by:Tom3333
  • 4
  • 2
7 Comments
 

Author Comment

by:Tom3333
ID: 36510171
No respond yet??
0
 
LVL 15

Expert Comment

by:yuk99
ID: 36511964
One option is to use subplot function while generating the figures as individual axes;

subplot(2,2,1)
% code for figure 1
% ...
subplot(2,2,2)
% code for figure 2
% ...
subplot(2,2,3)
% code for figure 3
% ...
subplot(2,2,4)
% code for figure 4
% ...

Open in new window

0
 
LVL 15

Expert Comment

by:yuk99
ID: 36512036
There are many File Exchange submissions related to your question. Some are just a better versions of SUBPLOT (used while creating the figures).

http://www.mathworks.com/matlabcentral/fileexchange/20003-panel
http://www.mathworks.com/matlabcentral/fileexchange/3696-subaxis-subplot

Others can combine separately generated figures into one figure.

http://www.mathworks.com/matlabcentral/fileexchange/3939-import-fig-file-to-axes
http://www.mathworks.com/matlabcentral/fileexchange/27713-montagefigures

Another one is SubplotPPT to save multiple figures to a single Powerpoint slide:
http://www.mathworks.com/matlabcentral/fileexchange/20949-subplotppt
You can then arrange it as you want and save as PNG.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:Tom3333
ID: 36513311
without  the use of subplot  (just to have 4 figure in one page) is it possible to export it?
0
 
LVL 15

Expert Comment

by:yuk99
ID: 36513610
No, you can export only one figure per page. If you want to put multiple figure on one page, you have to put them into one figure as axes. You can use SUBPLOT or arrange the axes manually with 'Position' property. Other alternatives I put above.

Please describe your problem in more details. How do you generate the figures? Why don't you like the SUBPLOT option?

You can also save multiple figures into one PDF or multipage TIF file, but they will be one figure per page. I think it's not what you want.
0
 
LVL 5

Expert Comment

by:KenIBrown2
ID: 36897988
You can sort of cheat by using printscreen button to save to the clipboard a bitmap of the screen image while youve got any plot or subplot displayed, then manipulate these and save in png format using your graphics editor of choice, eg PSP etc.
0
 
LVL 15

Accepted Solution

by:
yuk99 earned 50 total points
ID: 36904448
Tom3333,
Are you still interested in answer? Do you need automated solution in MATLAB?

The main problems with SUBPLOT are the following:
1. If you have multiple axes on even one of your figures. They will have to managed separately on subplot context, since subplot function actually returns only one axis. Sometime it can be hard.
2. Colormap has to be the same for all figures.
3. Large gaps between figures.

One way to avoid it:
1) save individual figures as PNG files
2) show all the images on one figure
3) print the figure to PNG

Here is the code after you save the individual figures:
ax(1) = axes('units','normalized','position',[0 0.5 0.5 0.5]);
ax(2) = axes('units','normalized','position',[0.5 0.5 0.5 0.5]);
ax(3) = axes('units','normalized','position',[0 0 0.5 0.5]);
ax(4) = axes('units','normalized','position',[0.5 0 0.5 0.5]);
set(ax,'visible','off')
imshow('fig1.png','parent',ax(1))
imshow('fig2.png','parent',ax(2))
imshow('fig3.png','parent',ax(3))
imshow('fig4.png','parent',ax(4))
print -dpng -r600 4figures.png

Open in new window

You need to set a good resolution in print command or appropriate figure size with set(gcf,'units','pixels','position',[0 0 width height]) before print.
IMSHOW requires Image Processing Toolbox. Can be substituted with IMAGE or IMAGESC, but need some additional steps.

If all your figures have the same size, here is the easier solution:
x = cell(2);
x{1,1} = imread('fig1.png');
x{1,2} = imread('fig2.png');
x{2,1} = imread('fig3.png');
x{2,2} = imread('fig4.png');
y = cell2mat(x); % will return an error if figures  size is different
imwrite(y,'4figures.png')

Open in new window

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This video teaches viewers about errors in exception handling.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now