Getframe to subplot
12 ビュー (過去 30 日間)
古いコメントを表示
Hello:
I am trying to take four frames below and make them into 4 subplots that I can insert into a latex document. The major problem is that when I generate the subplots, the images are too small to read. I have tried resizing the images, but that doesn't seem to work.
The four frames that I would like to include in my subplot are:
t = 1, 4, 11 and 16.
I am also attempting to write this to my hard drive automatically using imwrite, but I am not sure you can do this with multiple frames.
I bet this is something fairly simple, but I cannot figure out what I am doing wrong. My code is:
clc;
clear;
A = 1; B = 2; C = 2; D = 2; E = 0; N = 15
s = -100:.001:100;
[x,y] = meshgrid(-30:0.1:30);
f_r = A*C.*x.^2 - (A*C*E).*x - B*D.*y.^2;
fig_size = [1 1 500 400];
set(gcf,'Units','pixels','Position',fig_size,'Units',...
'inches')
for t = 1:N+1
contour(x,y,f_r,[10,10],'b');
hold on
f_i = (t-1)*(B*D-A*C)./(s.*(A*D+B*C)-B*C*E);
plot(s,f_i,'r-')
hold off
xlabel('x');
ylabel('y');
grid on;
title({['Real = ' num2str(A*C) 'x^2 - ' num2str(A*C*E) 'x - ' num2str(B*D) 'y^2'],
['Imaginary = ' ' t (' num2str(B*D-A*C) ') / (' num2str(A*D+B*C) 'x - ' num2str(B*C*E) ')']});
F(t) = getframe(gcf);
end
H = figure
subplot(2,2,1)
image(F(1).cdata);
%title('t = 0');
axis off
subplot(2,2,2)
image(F(4).cdata);
%title('t = 3');
axis off
subplot(2,2,3)
image(F(11).cdata);
%title('t = 10');
axis off
subplot(2,2,4)
image(F(16).cdata);
%title('t = 15');
axis off
imwrite(F(1).cdata, 'C:\Users\name\Documents\nodis1.png');
Any help that you could provide would be great,
Thanks Ima
0 件のコメント
回答 (2 件)
Doug Hull
2012 年 1 月 17 日
Have you thought of just leaving them as their own figures, and putting them into the paper that way as .EPS? Once you use getframe, you are turning the output into a bitmap, and it will not scale in a PDF.
0 件のコメント
Héctor Corte
2012 年 1 月 17 日
This code will fix your problem.
clc;
clear;
A = 1; B = 2; C = 2; D = 2; E = 0; N = 15
s = -100:.001:100;
[x,y] = meshgrid(-30:0.1:30);
f_r = A*C.*x.^2 - (A*C*E).*x - B*D.*y.^2;
fig_size = [100 100 1000 800];
set(gcf,'Units','pixels','Position',fig_size,'Units',...
'inches')
for t = 1:N+1
switch t
case 1
subplot(2,2,1)
dr=1;
case 4
subplot(2,2,2)
dr=1;
case 11
subplot(2,2,3)
dr=1;
case 16
subplot(2,2,4)
dr=1;
otherwise
dr=0;
end
if dr==1
contour(x,y,f_r,[10,10],'b');
hold on
f_i = (t-1)*(B*D-A*C)./(s.*(A*D+B*C)-B*C*E);
plot(s,f_i,'r-')
hold off
xlabel('x');
ylabel('y');
grid on;
title({['Real = ' num2str(A*C) 'x^2 - ' num2str(A*C*E) 'x - ' num2str(B*D) 'y^2'],
['Imaginary = ' ' t (' num2str(B*D-A*C) ') / (' num2str(A*D+B*C) 'x - ' num2str(B*C*E) ')']});
F(t) = getframe(gcf);
dr==0;
end
end
saveas(gcf, 'C:\Users\name\Documents\nodis1.png');
参考
カテゴリ
Help Center および File Exchange で Labels and Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!