How To do subplot in fallowing matlab Programme? it does two steps but after two steps it stops.
1 view (last 30 days)
Show older comments
%%%Based on paper"A novel Sensor based on a bragg fiber with a defect layer
%%programme for reflection throgh multilayer coaxial bragg fiber %%
close all
clear all
%%All refractive indices
n0=1.0;
nh=2.83; %2.83 %%high refractive index first layer
nL=1.66; %1.66 %%low refractive index first layer
nf=1.0; %%final medium refractive index
lambda0=1550*10^-9; %%normalised Design wavelength
%%All thickness parameters
dh=(lambda0/(4*nh)); %%thickness of high refractive index layer
dL=(lambda0/(4*nL)); %%thickness of low refractive index layer
d=0; %(lambda0/(4*nd)); %%defect layer thickness
uct=dh+dL; %%unit cell thickness
r0=1000*uct; %%initial core radius
%rN=r0+d+N*uct; %%radius of final layer having N unit cell and a defect layer
theta_1=0;
theta_2=15;
theta_3=30;
theta_4=45;
theta_5=60;
theta_6=75;
DD=[theta_1 theta_2 theta_3 theta_4 theta_5 theta_6];
%%For H Polarisation%%%
p0=377/n0; %%charecterstic impedence for zeroth layer
pf=377/nf; %%charecterstic impedence for final layer
ph=377/nh; %%charecterstic impedence for first high index layer
pL=377/nL; %%charecterstic impedence for first low index layer
m=0;
N=14;
rN=r0+d+N*uct;
%%range of operating wavelength
lambda1=1000*10^-9;
lambdai=2000*10^-9;
fid=fopen('transmitivity.txt','w')
for kk=1:6
theta1=DD(kk);
cnt=1;
for lambda=(1000:0.1:2000)*10^-9; %%Range of operating wavelength
%%using snells law all theta values %%
%theta1=0;
theta2=asind((n0/nh)*sind(theta1));
theta3=asind((nh/nL)*sind(theta2));
theta4=asind((nL/nf)*sind(theta3));
%%Different Wave vectors
% k0=(2*pi/lambda)*n0*sind(theta1); %%zeroth layer wave vector at operating wavelength
% kf=(2*pi/lambda)*nf*sind(theta4); %%final layer wave vector at operating wavelength
% kh=(2*pi/lambda)*nh*sind(theta2); %%first High layer wave vector at operating wavelength
% kL=(2*pi/lambda)*nL*sind(theta3); %%first low layer wave vector at operating wavelength
%
k0=(2*pi/lambda)*n0*cosd(theta1); %%zeroth layer wave vector at operating wavelength
kf=(2*pi/lambda)*nf*cosd(theta4); %%final layer wave vector at operating wavelength
kh=(2*pi/lambda)*nh*cosd(theta2); %%first High layer wave vector at operating wavelength
kL=(2*pi/lambda)*nL*cosd(theta3); %%first low layer wave vector at operating wavelength
%%Different Arguments%%
x0=k0*r0; %%for initial core
xf=kf*rN; %%for final region
y0=kh*r0; %%for first high layer
y1=kh*(r0+dh); %%for first high layer
z0=kL*(r0+dh); %%for second low layer
z1=kL*(r0+uct); %%for second low layer
%%For Core
c1_m0=(-besselh(m+1,1,x0)+(m/x0)*besselh(m,1,x0))/besselh(m,1,x0);
c2_m0=(-besselh(m+1,2,x0)+(m/x0)*besselh(m,2,x0))/besselh(m,2,x0);
c2_mf=(-besselh(m+1,2,xf)+(m/xf)*besselh(m,2,xf))/besselh(m,2,xf);
%%For High Index
m11=(pi/2)*y0*((-bessely(m+1,y0)+(m/y0)*bessely(m,y0))*besselj(m,y1)-(-besselj(m+1,y0)+(m/y0)*besselj(m,y0))*bessely(m,y1));
m12=-j*(pi/2)*(y0/ph)*(besselj(m,y0)*bessely(m,y1)-bessely(m,y0)*besselj(m,y1));
m21=j*(pi/2)*y0*ph*((-bessely(m+1,y0)+(m/y0)*bessely(m,y0))*(-besselj(m+1,y1)+(m/y1)*besselj(m,y1))-(-besselj(m+1,y0)+(m/y0)*besselj(m,y0))*(-bessely(m+1,y1)+(m/y1)*bessely(m,y1)));
m22=(pi/2)*y0*(besselj(m,y0)*(-bessely(m+1,y1)+(m/y1)*bessely(m,y1))-bessely(m,y0)*(-besselj(m+1,y1)+(m/y1)*besselj(m,y1)));
%%For Low Index
n11=(pi/2)*z0*((-bessely(m+1,z0)+(m/z0)*bessely(m,z0))*besselj(m,z1)-(-besselj(m+1,z0)+(m/z0)*besselj(m,z0))*bessely(m,z1));
n12=-j*(pi/2)*(z0/pL)*(besselj(m,z0)*bessely(m,z1)-bessely(m,z0)*besselj(m,z1));
n21=j*(pi/2)*z0*pL*((-bessely(m+1,z0)+(m/z0)*bessely(m,z0))*(-besselj(m+1,z1)+(m/z1)*besselj(m,z1))-(-besselj(m+1,z0)+(m/z0)*besselj(m,z0))*(-bessely(m+1,z1)+(m/z1)*bessely(m,z1)));
n22=(pi/2)*z0*(besselj(m,z0)*(-bessely(m+1,z1)+(m/z1)*bessely(m,z1))-bessely(m,z0)*(-besselj(m+1,z1)+(m/z1)*besselj(m,z1)));
%%Transfer Matrix
MAT1=[m11,m12;m21,m22];
MAT2=[n11,n12;n21,n22];
Final=(MAT2*MAT1)^(N);
inM=inv(Final);
%%Reflectance and Transmittance for non absorbing media
rd=((inM(2,1)-(j*p0*c2_m0)*inM(1,1))+j*pf*c2_mf*(inM(2,2)-(j*p0*c2_m0)*inM(1,2)))/(((j*p0*c1_m0)*inM(1,1)-inM(2,1))+j*pf*c2_mf*((j*p0*c1_m0)*inM(1,2)-inM(2,2)));
R=(abs(rd))*(abs(rd));
T=1-R;
Trans=100*T;
data_p(kk,cnt)=Trans;
cnt=cnt+1;
end
fprintf(fid,'%12.10e %12.10e\n',lambda, Trans);
end
lambda_p=(1000:0.1:2000)*10^-9;
lambda=(lambda_p)';
fclose(fid);
load transmitivity.txt
figure
subplot(6,1,1); plot(lambda,data_p(1,:));
subplot(6,1,2); plot(lambda,data_p(2,:));
subplot(6,1,3); Plot(lambda,data_p(3,:));
subplot(6,1,4); Plot(lambda,data_p(4,:));
subplot(6,1,5); Plot(lambda,data_p(5,:));
subplot(6,1,6); Plot(lambda,data_p(6,:));
1 Comment
Stephen23
on 14 Sep 2016
Edited: Stephen23
on 14 Sep 2016
@Ritesh Chaurasia: your code was not indented consistently, which is a bad practice because it makes code hard to read and therefore very easy to make mistakes. I fixed the code indentation in the MATLAB editor by selecting all of the text and clicking ctrl+i. In future keep in mind that consistent code formatting will reduce the chance of making mistakes.
Also your code shown many syntax warnings (in the editor, the orange lines in the RHS margin). You should fix these.
Answers (2)
Stephen23
on 14 Sep 2016
Edited: Stephen23
on 14 Sep 2016
The error message tells you exactly what the problem is. Did you read it ?
When MATLAB throws an error (because something in the code does not work), MATLAB prints an error message in the command window. This error message tells us lots of useful information, such where the error occurred, the reasons why the error was thrown, and the stack of function calls that resulted in that error being thrown.
The error message looks like this:
Undefined function 'Plot' for input arguments of type 'double'.
Error in Untitled (line 129)
subplot(6,1,3); Plot(lambda,data_p(3,:));
And so we immediately can see the problem: on the third plot call your wrote Plot (with a capital P) but it should be plot (all lowercase). All following plots have the same problem.
Summary: always read the error message!
0 Comments
Star Strider
on 14 Sep 2016
You can do the plots in a loop:
figure(1)
for k1 = 1:6
subplot(6,1,k1); plot(lambda,data_p(k1,:));
grid
end
0 Comments
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!