Subplotting programmatically for varying amounts of subplots
5 次查看(过去 30 天)
显示 更早的评论
Hi, It may be that there is terminology or expressions I am not aware of and that this question has already been answered but I cannot find it. I have a number of files to deal with, usually 4, which I can competently subplot in a loop. If a=the number of files then i designated the subplot area as rows=a/2 and columns = a. This is fine for when I have four files, what I do not know how to handle is the case where a =3 or 5.
I would like to know how to approach creating another figure when necessary and to handle the cases where a is less than 4.
I now I could just plot more graphs on a single page but they would be unreadable once transferred into the pdf report generator I am using.
2 个评论
Jan
2017-4-5
If n is the number of diagrams, your figure should contain n/2 rows and n columns? Do you mean n/2 columns?
采纳的回答
Jan
2017-4-5
编辑:Jan
2017-4-5
If your goal is to have up to 2x2 suplots on each figure:
Folder = 'C:\Temp\';
FileList = dir(fullfile(Folder, '*.mat')); % Or whatever
for iFile = 1:numel(FileList)
data = load(fullfile(Folder, FileList(iFile).name);
index = mod(iFile - 1, 4) + 1; % [EDITED] mod(iFile, 4) is not sufficient
if index == 1 % Create a new figure
FigH = figure;
end
AxesH = subplot(2, 2, index, 'Parent', FigH);
plot(data.x, data.y); % Adjust to your needs of course
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!