Inconsistent row/column dimensions.

l=633*(10)^(-9);
k0=(2*pi)/l;
nc=1.33;
na=1.43265;
nf=1.59;
nm=0.064+1i*4;
ns=1.49;
a=54:0.01:70
df=1:1:300;
nf=1.59;
k0=(2*pi/633);
Nm=nf*sind(a);
Snc=zeros(length(a),length(df));
Sna=zeros(length(a),length(df));
Sda=zeros(length(a),length(df));
p=1;
ds=((1-p)./(k0.*sqrt(Nm.^2-ns.^2)))+(p./((Nm./nf).^2+(Nm./ns).^2-1).*(k0.*sqrt(Nm.^2-ns.^2)));
dc=((1-p)./(k0.*sqrt(Nm.^2-nc.^2)))+(p./((Nm./nf).^2+(Nm./nc).^2-1).*(k0.*sqrt(Nm.^2-nc.^2)));
da=((1-p)./(k0.*sqrt(Nm.^2-na.^2)))+(p./((Nm./nf).^2+(Nm./na).^2-1).*(k0.*sqrt(Nm.^2-na.^2)));
Snc= ((nc/Nm).*((nf.^2-Nm.^2)./(nf.^2-nc.^2)).*(dc./(ds+df+dc)).*(2.*(Nm.^2./nc.^2)-1));
Sna= ((na./Nm).*((nf.^2-Nm.^2)./(nf.^2-na.^2)).*(da./(ds+df+da)).*(2.*(Nm.^2./na.^2)-1));
Sda= (((nf.^2-Nm.^2)./(Nm.*(ds+df+dc))).*((na.^2-nc.^2)./(nf.^2-nc.^2)).*((((Nm./nc).^2)+((Nm./na).^2)-1)./( ((Nm./nc).^2)+((Nm./nf).^2)-1))).^p;
plot(df,Snc)

 采纳的回答

l=633*(10)^(-9);
k0=(2*pi)/l;
nc=1.33;
na=1.43265;
nf=1.59;
nm=0.064+1i*4;
ns=1.49;
a=54:0.01:70 ;
df=linspace(1,300,length(a));
nf=1.59;
k0=(2*pi/633);
Nm=nf*sind(a);
p=1;
ds=((1-p)./(k0.*sqrt(Nm.^2-ns.^2)))+(p./((Nm./nf).^2+(Nm./ns).^2-1).*(k0.*sqrt(Nm.^2-ns.^2)));
dc=((1-p)./(k0.*sqrt(Nm.^2-nc.^2)))+(p./((Nm./nf).^2+(Nm./nc).^2-1).*(k0.*sqrt(Nm.^2-nc.^2)));
da=((1-p)./(k0.*sqrt(Nm.^2-na.^2)))+(p./((Nm./nf).^2+(Nm./na).^2-1).*(k0.*sqrt(Nm.^2-na.^2)));
Snc= ((nc./Nm).*((nf.^2-Nm.^2)./(nf.^2-nc.^2)).*(dc./(ds+df+dc)).*(2.*(Nm.^2./nc.^2)-1));
Sna= ((na./Nm).*((nf.^2-Nm.^2)./(nf.^2-na.^2)).*(da./(ds+df+da)).*(2.*(Nm.^2./na.^2)-1));
Sda= (((nf.^2-Nm.^2)./(Nm.*(ds+df+dc))).*((na.^2-nc.^2)./(nf.^2-nc.^2)).*((((Nm./nc).^2)+((Nm./na).^2)-1)./( ((Nm./nc).^2)+((Nm./nf).^2)-1))).^p;
plot(df,Snc)
Warning: Imaginary parts of complex X and/or Y arguments ignored.

8 个评论

how we use zeros in this program
use of zeros of the df
Did you raise any question regarding use of zeros of df? What was your question and what you are expecting?
if you have idea of using zeros so pl help because I have use zeros in initial program
I know zero is represented by 0. How and why you want to use here?
for exaple this type of program example program for use of zeros for initialization
function kk1
clc;clear;close all;
l=633;
c = 1;
k0=2*pi/l;
ea=1.39;
da=1:300;
theta=1:70;
y=zeros(length(theta),length(da));
np=1.5;
x=(2*pi/l)*np*sind(theta);
function y=f(theta,da)
for i=1:length(theta)
iter = 0;
for j=1:length(da)
iter
ka=k0*sqrt(ea-x.^2);
f=(1-exp(2*1i.*da(j).*ka(i)))/(1+exp(2*1i.*da(j).*ka(i)));
%pfms=2*atan(1i*a.*b);
y(i,j)=2*atan(1i*c.*f);
% disp(y);
iter = iter + 1;
end
end
end
plot(da,y )
end
Jeez you want to use initilization?
If you are using a loop and filling values into it, you have to initalize the array using zeros.
If you are not using loop and getting the LHS by vectorization, no loop is needed.

请先登录,再进行评论。

更多回答(1 个)

It seems there is a problem in Snc solution. ds and dc are vectors of 1601 elements whereas df has 300 elements.
Snc= ((nc/Nm).*((nf.^2-Nm.^2)./(nf.^2-nc.^2)).*(dc./(ds+df+dc)).*(2.*(Nm.^2./nc.^2)-1));
The same in Sna line:
Sna= ((na./Nm).*((nf.^2-Nm.^2)./(nf.^2-na.^2)).*(da./(ds+df+da)).*(2.*(Nm.^2./na.^2)-1));
I don't know the aim of df but try initializing the same length as ds.

类别

帮助中心File Exchange 中查找有关 Programming 的更多信息

产品

版本

R2021b

标签

Community Treasure Hunt

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

Start Hunting!

Translated by