main title on subplot using for loop

2 次查看(过去 30 天)
son
son 2014-8-28
hi, i created a whole programme but don't know how to create one sub title using for loop:
if type =1 => main title: G.652 fibre
if type =2 => main title: G.653 fibre
if type =3 => main title: G.655 fibre
clear all
close all
%%Insert value in Matlab
n=[10 40 80];
p=1*10^-3;
delta_lambda = 0.4*10^-9;
distance=1000;
type=1:3;
alphadbset=[0.20 0.22 0.23];
dispersionset=[16 0 3];
slopeset=[0.080 0.075 0.050];
Aset=[80 50 72];
j1 = 1:n(1);
S1 = zeros(1,length(j1));
if mod(n(1),2)==1
for k = 1:length(j1)
if mod(j1(k),2) == 0
S1(k) = (n(1)^2-1)/4 + n(1)*j1(k)/2 - j1(k)^2/2 - n(1) + j1(k)/2;
else
S1(k) = (n(1)^2+1)/4 + n(1)*j1(k)/2 - j1(k)^2/2 - n(1) + j1(k)/2;
end
end
else
for k = 1:length(j1)
S1(k) = n(1)^2/4 + n(1)*j1(k)/2 - j1(k)^2/2 - n(1) + j1(k)/2;
end
end
j2 = 1:n(2);
S2 = zeros(1,length(j2));
if mod(n(2),2)==1
for k = 1:length(j2)
if mod(j2(k),2) == 0
S2(k) = (n(2)^2-1)/4 + n(2)*j2(k)/2 - j2(k)^2/2 - n(2) + j2(k)/2;
else
S2(k) = (n(2)^2+1)/4 + n(2)*j2(k)/2 - j2(k)^2/2 - n(2) + j2(k)/2;
end
end
else
for k = 1:length(j2)
S2(k) = n(2)^2/4 + n(2)*j2(k)/2 - j2(k)^2/2 - n(2) + j2(k)/2;
end
end
j3 = 1:n(3);
S3 = zeros(1,length(j3));
if mod(n(3),2)==1
for k = 1:length(j3)
if mod(j3(k),2) == 0
S3(k) = (n(3)^2-1)/4 + n(3)*j3(k)/2 - j3(k)^2/2 - n(3) + j3(k)/2;
else
S3(k) = (n(3)^2+1)/4 + n(3)*j3(k)/2 - j3(k)^2/2 - n(3) + j3(k)/2;
end
end
else
for k = 1:length(j3)
S3(k) = n(3)^2/4 + n(3)*j3(k)/2 - j3(k)^2/2 - n(3) + j3(k)/2;
end
end
for type=1:3
alphadb=alphadbset(type);
dispersion=dispersionset(type);
slope=slopeset(type);
A=Aset(type);
alpha = alphadb/(10*log10(exp(1)));
s = slope*10^3;
d = 6;
lambda = 1.550*10^-6;
Aeff = A*10^-12;
c = 3*10^8;
n2 = 2.68*10^-20;
nsp=1.3;
h=6.626*10^-34;
B=12.5*10^9;
D = dispersion*10^-6;
delta_belta = 2 * pi * c * (delta_lambda^2) / (lambda^2)* (D+s*delta_lambda)*10^3;
L=30:1:100;
m=ceil(distance./L)-1;
Leff=(1-exp(-alpha.*L))/alpha;
eta = (alpha^2) / ((alpha^2) + (delta_belta^2))*(1+((4*exp(-alpha.*L).*(sin(delta_belta.*L/2)).^2)./((1-exp(-alpha.*L)).^2)));
gamma=(2*pi*n2)/(lambda*Aeff);
Pfwm= eta .*(d^2/9).*(gamma^2).*((Leff*10^3).^2).*(p^3).*exp(-alpha.*L);
Pfwmchannelmax10=max(S1).*(Pfwm.*((sin(m.*delta_belta.*L./2)).^2)./((sin(delta_belta.*L/2)).^2)+(eta .*(d^2/9).*(gamma^2).*((Leff*10^3).^2).*(p^3).*exp(-alpha.*(distance-m.*(distance-m.*L)))));
Pfwmchannelmax40=max(S2).*(Pfwm.*((sin(m.*delta_belta.*L./2)).^2)./((sin(delta_belta.*L/2)).^2)+(eta .*(d^2/9).*(gamma^2).*((Leff*10^3).^2).*(p^3).*exp(-alpha.*(distance-m.*(distance-m.*L)))));
Pfwmchannelmax80=max(S3).*(Pfwm.*((sin(m.*delta_belta.*L./2)).^2)./((sin(delta_belta.*L/2)).^2)+(eta .*(d^2/9).*(gamma^2).*((Leff*10^3).^2).*(p^3).*exp(-alpha.*(distance-m.*(distance-m.*L)))));
%%Calculation ASE noise:
G=exp(alpha.*L);
Pase=2*nsp*h*c/lambda*B .*(G-1).*m;
Pasedbm=30+(10*log(Pase));
%%Optical signal-to-noise ratio per channel:
Pnoisemax10=Pfwmchannelmax10+Pase;
Pnoisemax40=Pfwmchannelmax40+Pase;
Pnoisemax80=Pfwmchannelmax80+Pase;
Pout=p*exp(-alpha.*(distance-m.*L));
OSNR10=10*log(Pout./Pnoisemax10);
OSNR40=10*log(Pout./Pnoisemax40);
OSNR80=10*log(Pout./Pnoisemax80);
figure(type)
FigHandle = figure(type);
set(FigHandle, 'Position', [400, 350, 1400, 750]);
subplot(3,1,1);
plot(L,OSNR10,'m')
title('Optical signal-to-noise ratio for 10 channels','Color','b');
xlabel('Amplifier spacing (km)','Color','b');
ylabel('OSNR (dB)','Color','b');
grid
subplot(3,1,2);
plot(L,OSNR40,'r')
title('Optical signal-to-noise ratio for 40 channels','Color','b');
xlabel('Amplifier spacing (km)','Color','b');
ylabel('OSNR (dB)','Color','b');
grid
subplot(3,1,3);
plot(L,OSNR80,'k')
title('Optical signal-to-noise ratio for 80 channels','Color','b');
xlabel('Amplifier spacing (km)','Color','b');
ylabel('OSNR (dB)','Color','b');
grid
end
  1 个评论
Geoff Hayes
Geoff Hayes 2014-8-28
son - I ran your above code, and a title was created for each subplot. What exactly do you mean by don't know how to create one sub title using for loop? Do you want a title for each figure (this is missing), as well as one title for each subplot (this works)?

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2014-8-28
  2 个评论
Image Analyst
Image Analyst 2014-8-29
Download the file to a folder on your search path, and then call it like it probably tells you in the instructions. I haven't run it in a log time, if ever.

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by