command for one copy of 3 figure in subplot form and put it in only one picture in bmp format
1 view (last 30 days)
Show older comments
anyone know how can copy a figure in subplot form and put(for example in .bmp format) it in a specified folder. there are 3 figures in subplot form
0 Comments
Accepted Answer
Fangjun Jiang
on 6 Sep 2011
saveas() works on a figure not on a axes, so the following code will save the whole figure no matter running saveas(h,...) or saveas(s2,...). If you really want to save the subplot, you need to plot that subplot in a separate figure and then save it. Maybe you can do further re-sizing to achieve the sub-plot effect.
>> h=figure;
>> s1=subplot(311);plot(1:10)
>> s2=subplot(312);plot(rand(10,1))
>> s3=subplot(313);plot(magic(3))
>> saveas(s2,'subplot2','jpg')
>> saveas(h,'AllPlot','jpg')
More Answers (1)
Grzegorz Knor
on 6 Sep 2011
Is this what you meant?
% example figure
subplot(311)
plot(rand(100,1),'r')
subplot(312)
bar(rand(5,1))
subplot(313)
semilogy(1:10)
% save
print(gcf,'-dbmp','C:\Documents and Settings\user\My Documents\MATLAB\picture.bmp')
2 Comments
Grzegorz Knor
on 6 Sep 2011
Alternatively:
% example figure
s(1) = subplot(311);
plot(rand(100,1),'r')
s(2) = subplot(312);
bar(rand(5,1))
s(3) = subplot(313);
semilogy(1:10)
% save
h = figure;
for k=1:3
copyobj(s(k),h)
print(h,'-dbmp',['C:\Documents and Settings\grzesiek\My Documents\MATLAB\picture' num2str(k)])
clf
end
close(h)
or
% save
h = figure;
for k=1:3
copyobj(s(k),h)
set(gca,'Units','normal','Position',[.1 .1 .8 .8])
print(h,'-dbmp',['C:\Documents and Settings\grzesiek\My Documents\MATLAB\picture' num2str(k)])
clf
end
close(h)
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!