how to subplot n figures (pcolor) using for loop

조회 수: 4 (최근 30일)
SanSun
SanSun 2020년 9월 29일
편집: Adam Danz 2020년 9월 30일
Hello everyone.
I have n.fig saved files (pcolor figures) that I want to plot in one new subplot (n X 2). Can anyone please help me out here? I will be really really grateful :)
clear all
clc
% Open .fig
field = 'C:\xxxxxxx';
rep = fullfile(field);
if exist(rep, 'file')~=7
error('field does not exist');
else
ext = '*.fig';
chemin = fullfile(rep,ext);
list = dir(chemin);
nFig = numel(list);
newAxes = [];
% Open each figure and copy content
for i = 1:nFig
% Open fig-i
filename = fullfile(rep,list(i).name);
fighand = openfig(filename,'invisible');
% Get axis handle (assumption: only 1 axes in figure)
axHand = findobj(fighand, 'Type', 'Axes');
if i==1
fh = figure();
newAxes = copyobj(axHand, fh);
hold(newAxes, 'on')
h = newAxes.Children;
else
h=subplot(nFig,2,i);
end
% % Close fig-i
close(fighand)
end
end
  댓글 수: 4
VBBV
VBBV 2020년 9월 30일
편집: VBBV 2020년 9월 30일
Just use hold on without get and plothandles shown below
% if true
% code
% end
h(i) = subplot(nFig,2,i);
hold(h(i),'on');
VBBV
VBBV 2020년 9월 30일
You can also use nexttile and tiledlayout instead of subplot as
% if true
% code
%end
tiledlayout(nFig,2)
nexttile
plot(...)
Within the loop

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by