Hi everyone, i've a problem using the command subplot. In a for loop i plot every column of a matrix in a figure, assigning each one of them a title and names to each label. Now my objective is to subplot in each one of the figures a zoomed section of the previous plot, so making it short, in the figure i I have to plot the i-th column and to subplot a zoomed section of the i-th column, assigning to the zoomed plot the same name as the upper one, just adding to the title the string 'Comp'. the zoomed section is the same for all the main figures i plot, so on each one of them i make the same zoom. Here is the try i made:
load newdataParameters
NR_Serving_SS_RSRP=newdataParameters(:,4);
NR_Serving_SS_SINR=newdataParameters(:,5);
NR_PCC_Avg_CQI=newdataParameters(:,33);
NR_PCC_PDSCH_RB_Numbers=newdataParameters(:,38);
NR_PCC_DL_PHY_Throughput=newdataParameters(:,51);
Parameters_to_Plot=[NR_Serving_SS_RSRP,NR_Serving_SS_SINR,NR_PCC_Avg_CQI,NR_PCC_PDSCH_RB_Numbers,NR_PCC_DL_PHY_Throughput];
Name_List={'NR-Serving-SS-RSRP','NR-Serving-SS-SINR','NR-PCC-Avg-CQI','NR-PCC-PDSCH-RB-Number/s','NR-PCC-DL-PHY-Throughput'};
Ylabel_List={'dBm','dB','Naturals','Number/s','Mbit/s'};
[Rows_number,Columns_number]=size(Parameters_to_Plot);
%% Plot
Sample_Start1=input('From which sample to start your full analysis?');
Sample_End1=input('Until which sample you want to see your normal analysis?');
Sample_Start2=input('From which sample to start your zoomed analysis?');
Sample_End2=input('Until which sample you want to see your zoomed analysis?');
Comp_Start1=input('From which sample the Comp strategy activates?');
Comp_End1=input('Until which sample the Comp strategy keeps being active?');
Exitation=strncmp(upper(input('Do you want to zoom another comp activation window? [Y]es or [N]o : ','s')),'Y',1);
input('Enter to continue...');
for i=1:Columns_number
if Exitation
Comp_Start2=input('From which sample the 2nd Comp strategy activates?');
Comp_End2=input('Until which sample the 2nd Comp strategy keeps being active?');
end
figure
A=Parameters_to_Plot(:,i);
plot(Parameters_to_Plot(:,i) );
title(Name_List{i})
xlabel('Samples')
ylabel(Ylabel_List{i})
grid on
subplot(2,i,1)
signal=Parameters_to_Plot(:,i).';
t2=linspace(Sample_Start2,Sample_End2,(Sample_End2-Sample_Start2)+1);
indexOfInterest =(A(Sample_Start2:Sample_End2,:));
plot(t2,indexOfInterest)
hold on
plot([Comp_Start1 Comp_Start1],ylim,'--r')
plot([Comp_End1 Comp_End1],ylim,'--r')
text(Comp_Start1-35,-90,'First Comp activates now \rightarrow')
text(Comp_End1,-90,'\leftarrow Comp ends now ')
plot([Comp_Start2 Comp_Start2],ylim,'--r')
plot([Comp_End2 Comp_End2],ylim,'--r')
text(Comp_Start2-35,-100,'Second Comp activates now \rightarrow')
text((Comp_End2-25),-100,'\leftarrow Second Comp ends now ')
hold off
grid
axis tight

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 10 月 4 日

0 投票

It doesn't look like you are using subplot correctly. The most current way to do this is using tiledlayout. There is a good example of how to use this approach on this page.
If you want to stick with subplot, assign every plot on the figure to a subplot.
subplot(2,1,1)
<code for creating first plot>
subplot(2,1,2)
<code for creating second plot>

2 件のコメント

Alessio Calce
Alessio Calce 2020 年 10 月 4 日
How could I apply tiledlayout to my case?
Cris LaPierre
Cris LaPierre 2020 年 10 月 4 日
Take a look at these examples.

サインインしてコメントする。

質問済み:

2020 年 10 月 4 日

コメント済み:

2020 年 10 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by