Subplot ID in a loop where k> number of plot locations for a single page

조회 수: 1 (최근 30일)
Stephen Devlin
Stephen Devlin 2017년 4월 10일
댓글: Jan 2017년 4월 11일
Hi, This is a tricky one for me to explain. I have q files, and want to subplot them on a page with 4 locations. Due to considerations for how the figures/pages will be looked at in a pdf I am using a (2,4,q) subplot and plotting a distribution in (2,2,1:2) etc. It would be easier to just have (2,2,q) but they would not look so good in the final pdf.
For q being no higher than 4 I use
subplot(PlotsPerPage/2,PlotsPerPage,[q+q-1, q+q])
which works nicely. But when q>4 it falls over. I think my problem is more of a math issue than matlab but I am hoping that there will be a way to do take use of a matlab function maybe in a way I am not aware of. I can do this longhand by having if statements for when q=5:8 or q=9:12 etc but would like to avoid that as I can see q going to a very high number by the end of the year.
  댓글 수: 2
Jan
Jan 2017년 4월 10일
I'm confused by the question. What does "using a (2,4,q) subplot and plotting a distribution in (2,2,1:2) etc." mean? Do you really mean "subplot(PlotsPerPage/2,PlotsPerPage, [q+q-1, q+q])"? Then the pages contains more plots then PlotsPerPage and for q = 2 you get the position [3, 4]. Sorry, I cannot follow you.
You currently have:
subplot(2,4,q)
What fails for q > 4? Do you want to display 8 diagrams per page? What happens and what do you want to happen?
Stephen Devlin
Stephen Devlin 2017년 4월 10일
편집: Stephen Devlin 2017년 4월 10일
Hi Jan, I only want to display 4 diagrams per page. Each diagram will fill two subplot locations on a page, so when q=1 it would fill subplot locations 1&2, q=2 it would fill subplot locations 3&4, q=3 it would fill subplot locations 5&6, q=4 it would fill subplot locations 7&8.
Using [q+q-1, q+q] when q=1 q+q-1=1 and q+q=2 giving the subplot location [1 2] for when q=1. This gives a stretched out subplot that looks better in my pdf report.
Where it 'falls over' is when say q=7, and I cannot figure out the maths then for the loop that will work for the q values for both 1:4 and >4.

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

채택된 답변

Jan
Jan 2017년 4월 10일
Do you mean:
q = 1:10
qq = mod(q - 1, 4) + 1
>> 1 2 3 4 1 2 3 4 1 2
Then the values of qq are restricted to 1:4. I assume you have to open a new figure when qq is 1 - as shown in your other thread.
  댓글 수: 3
Stephen Devlin
Stephen Devlin 2017년 4월 10일
Hi Jan, Something odd happens with my code and I am not sure why, the first loop was dealing with the case where q (which is the number of Volume columns (nVolCol)) q=1:4. That displays a figure with 4 subplots the way i want.
With the second loop I only seem to see the last subplot plotted, and in the wrong place.
figure('units','normalized','outerposition',[0 0 1 1]);
PlotsPerPage = 4
for q = 1:PlotsPerPage
new_str=strrep(files(q).name, '_', ' ');
new_str2=strrep(new_str, '.xlsx', ' ');
new_str3=strrep(new_str2, 'RA 20.5V 2US', ' ');
%subplot(2,2,n)
subplot(PlotsPerPage/2,PlotsPerPage,[q+q-1, q+q])
counts = hist(loopDataVol(:,q),centers);
bar(counts / sum(counts));
set(gca,'FontSize',10,'FontWeight','Bold')
set(0,'DefaultAxesLineStyleOrder',{'-','--',':'}) %or whatever order you want
% title('Velocity Distribution Row1')
title([' XXXXXXXX VolDist ',new_str3]);
end
if nVolCol>4
figure('units','normalized','outerposition',[0 0 1 1]);
for q=5:8
new_str=strrep(files(q).name, '_', ' ');
new_str2=strrep(new_str, '.xlsx', ' ');
new_str3=strrep(new_str2, 'RA 20.5V 2US', ' ');
%subplot(2,2,n)
subplot(2,4,[mod(q - 1, 4) + 1, mod(q - 1, 4) + 2])
counts = hist(loopDataVol(:,q),centers);
bar(counts / sum(counts));
set(gca,'FontSize',10,'FontWeight','Bold')
set(0,'DefaultAxesLineStyleOrder',{'-','--',':'}) %or whatever order you want
% title('Velocity Distribution Row1')
title([' YYYYYYYYY VolDist ',new_str3]);
end
end
Jan
Jan 2017년 4월 11일
If "subplot(PlotsPerPage/2,PlotsPerPage,[q+q-1, q+q])" works reliably, then use in the 2nd loop:
for q = 5:8
qq = mod(q - 1, 4) + 1;
subplot(PlotsPerPage/2,PlotsPerPage,[qq+qq-1, qq+qq])

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

추가 답변 (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