Solved

Multiple figure in matlab

Posted on 2011-09-08
7
962 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

825 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