Solved

Multiple figure in matlab

Posted on 2011-09-08
7
996 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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:Kenneth Brown
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

688 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