Index in position 2 exceeds array bounds. Index must not exceed 1. Error in metal6 (line 60) M4=[m411(1,j),m412(1,j);m421(1,j),m422(1,j)];
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
theta=13:0.1:90;
lambda=1550;%wavelength in vacuum in nm
eps1=2.28;eps2=1.87;eps3=2.28;eps4=1.87;eps5=2.28;
d=[600,400,600,600];%thickness of layer in nm for layer 2,3,4
mu=[1,1,1,1,1]; %permeability of every layer
eps=[eps1,eps2,eps3,eps4,eps5];
n=zeros(1,5);%refractive index
T=zeros(1,length(theta));
for s=1:5
n(s)=sqrt(eps(s)*mu(s));
end
na=1.370;
n0=1.30;
nk1=sqrt((eps(1)-(n(1)^2)*(sind(theta)).^2));%optical admittance inc layer
nk2=sqrt((eps(2)-(n(2)^2)*(sind(theta)).^2));%optical admittance second layer
nk3=sqrt((eps(3)-(n(3)^2)*(sind(theta)).^2));%optical admittance third layer
nk4=sqrt((eps(4)-(n(4)^2)*(sind(theta)).^2));%optical admittance fourth layer
nk5=sqrt((eps(5)-(n(5)^2)*(sind(theta)).^2));
%optical admittance fith layer
q1=nk1/eps1;
q2=nk2/eps2;
q3=nk3/eps3;
q4=nk4/eps4;
q5=nk5/eps5;
delta1=((2*pi)./lambda).*d(1).*sqrt((eps(1)-(n(1).^2).*(sind(theta)).^2));
delta2=((2*pi)./lambda).*d(2).*sqrt((eps(2)-(n(2).^2).*(sind(theta)).^2));
delta3=((2*pi)./lambda).*d(3)*sqrt((eps(3)-(n(3).^2).*(sind(theta)).^2));
delta4=((2*pi)./lambda).*d(4)*sqrt((eps(4)-(n(4).^2).*(sind(theta)).^2));
%ga=((2*pi)./lambda)*sqrt((eps(1)-(na.^2)*(sind(theta)).^2));
%g0=((2*pi)./lambda)*sqrt((eps(1)-(n0.^2)*(sind(theta)).^2));
m111=cosd(delta1);
m112=1i*sind(delta1/q1);
m121=1i*q1.*sind(delta1);
m122=cosd(delta1);
m211=cosd(delta2);
m212=1i*sind(delta2/q2);
m221=1i*q2.*sind(delta2);
m222=cosd(delta2);
%//%M2=[m211,m212;m221,m222];
m311=cosd(delta3);
m312=1i*sind(delta3/q3);
m321=1i*q3.*sind(delta3);
m322=cosd(delta2);
%//%M3=[m311, m312;m321,m322];
m411=cosd(delta4);
m412=1i*sind(delta4/q4);
m421=1i*q4.*sind(delta4);
m422=cosd(delta3);
%M4=[m411, m412;m421,m422];
Mtot=zeros(2,length(theta));
for j=1:length(theta)
M4=[m411(1,j),m412(1,j);m421(1,j),m422(1,j)];
M3=[m311(1,j),m312(1,j);m321(1,j),m322(1,j)];
M2=[m211(1,j),m212(1,j);m221(1,j),m222(1,j)];
M1=[m111(1,j),m112(1,j);m121(1,j),m122(1,j)];
Mtot=M4*M3*M2*M1;
%T(j)=((nk5(j)/nk1(j))*(abs((2*nk1(j)/((Mtot(1,1)+Mtot(1,2).*nk5(j)).*nk1(j)+(Mtot(2,1)+Mtot(2,2).*nk5(j))))).^2));
%//%T(j)=(na^2*g0*M11-n0^2*ga*M22+g0*ga*M12-na^2*n0^2*M21)/(na^2*g0*M11+n0^2*ga*M22+g0*ga*M12+na^2*n0^2*M21);
% T(j) =((na^2.*g0.*Mtot(1,1)-n0^2.*ga.*Mtot(1,2)+g0.*ga.*Mtot(2,1))/(na^2.*g0.*Mtot(1,1)+n0^2.*ga.*Mtot(1,2)+g0.*ga.*Mtot(2,1)));
T(j) =(Mtot(1,1)+Mtot(1,2).*q1(j)).*q5(j)-(Mtot(2,1)+Mtot(2,2).*q5(j)) /(Mtot(1,1)+Mtot(1,2).*q1(j)).*nk5(j)+(Mtot(2,1)+Mtot(2,2).*q5(j)).^2;
end
figure(1);
plot(theta,abs(T));
xlabel('incident angle');
ylabel('transmmission, s-pol');
this is the error showing program Index in position 2 exceeds array bounds. Index must not exceed 1 Error in metal6 (line 60) M4=[m411(1,j),m412(1,j);m421(1,j),m422(1,j)];
how to resolve it
0 commentaires
Réponse acceptée
KSSV
le 24 Jan 2022
Few of your variables like m212, m312, m412 are scalars i.e. 1x1 size and you are treating them as vectors and extracting more number of elements.
Example:
A = rand ;
A(1) % no error
A(2) % erros, as A is a scalar and got only one value
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!