Saving full screen multiple figures

조회 수: 18 (최근 30일)
Sharath Nagaraju
Sharath Nagaraju 2021년 1월 20일
댓글: Image Analyst 2021년 1월 21일
Hello,
I have four files with ten columns of data. They have common x-axis, array of t.
I am plotting them using for loop
The code looks something like below;
For i=1:10
figure(1)
handle1(i)=plot(t(:,1), File1(:,i));
Legend1{i}=sprintf('Run number: %d',i);
hold on
figure(2)
handle1(i)=plot(t(:,1), File2(:,i));
Legend2{i}=sprintf('Run number: %d',i);
hold on
figure(3)
handle3(i)=plot(t(:,1), File3(:,i));
Legend3{i}=sprintf('Run number: %d',i);
hold on
figure(4)
handle4(i)=plot(t(:,1), File4(:,i));
Legend4{i}=sprintf('Run number: %d',i);
hold on
end
legend(handle1,Legend1, ‘location’, ‘northwestoutside’);
legend(handle2,Legend2, ‘location’, ‘northwestoutside’);
legend(handle2,Legend2, ‘location’, ‘northwestoutside’);
legend(handle2,Legend2, ‘location’, ‘northwestoutside’);
Now, saving figure after legend will reduce the figure aspect ratio. I would like to save figure in full-screen mode.
i.e.saveas(figure(2), ‘Figure2.tiff’,’Tiff’);
I did some search and found the following code
FigH = figure('Position', get(0, 'Screensize'));
F = getframe(FigH);
I am unable to figure out as to how I can incorporate figure number inside above-mentioned command. i.e. inside figure(‘position’, get(0,’Screensize’))
I am learning matlab now. I also welcome any additional comment on the code itself.
  댓글 수: 2
Image Analyst
Image Analyst 2021년 1월 21일
Are you trying to save 40 figures? Or 4 or 10?
Sharath Nagaraju
Sharath Nagaraju 2021년 1월 21일
4 figures in total. Each will have 10 lines.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2021년 1월 21일
Try this:
clear all;
close all;
clc;
format long g;
format compact;
fontSize = 18;
fprintf('Beginning to run %s.m ...\n', mfilename);
% Create sample data.
File1 = rand(5, 10);
File2 = rand(5, 10);
File3 = rand(5, 10);
File4 = rand(5, 10);
t = rand(5, 10);
handle1 = figure;
handle2 = figure;
handle3 = figure;
handle4 = figure;
plotColors = jet(10);
for k=1:10
thisColor = plotColors(k, :);
figure(handle1)
plot(t(:,1), File1(:,k), '-', 'Color', thisColor);
legendStrings{k}=sprintf('Run number: %d',k);
hold on
figure(handle2)
plot(t(:,1), File2(:,k), '-', 'Color', thisColor);
hold on
figure(handle3)
plot(t(:,1), File3(:,k), '-', 'Color', thisColor);
hold on
figure(handle4)
plot(t(:,1), File4(:,k), '-', 'Color', thisColor);
hold on
end
figure(handle1);
legend(legendStrings, 'location', 'northwestoutside');
exportgraphics(handle1, 'Plot1.png'); % Save figure to disk.
figure(handle2);
legend(legendStrings, 'location', 'northwestoutside');
exportgraphics(handle1, 'Plot2.png'); % Save figure to disk.
figure(handle3);
legend(legendStrings, 'location', 'northwestoutside');
exportgraphics(handle1, 'Plot3.png'); % Save figure to disk.
figure(handle4);
legend(legendStrings, 'location', 'northwestoutside');
exportgraphics(handle1, 'Plot4.png'); % Save figure to disk.
% You can maximize each one before saving if you want, like this:
g = gcf;
g.WindowState = 'maximized';
fprintf('Done running %s.m.\n', mfilename);
  댓글 수: 2
Sharath Nagaraju
Sharath Nagaraju 2021년 1월 21일
Thanks. Just a note: I used saveas(gcf,..) instead of exportgraphics as I was getting error with it.
Image Analyst
Image Analyst 2021년 1월 21일
exportgraphics() only started with r2020a.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by