Vectors must be the same length.

theta=30:0.01:50;
lambda=633;
k0=2*pi/lambda;
e1=1.50^2;e3=1.33^2;e2=(0.12+1i*3.5)^2;
n1=1.50;n3=1.33;n2=0.12+1i*3.433;
d2=50;
n1=1.50;
x=n1*sind(theta);
k1=k0.*sqrt(e1.*mu1-x.^2);
k2=k0.*sqrt(e2.*mu2-x.^2);
k3=k0.*sqrt(e3.*mu3-x.^2);
q1=sqrt(e1-x.^2)./e1;
q2=sqrt(e2-x.^2)./e2;
q3=sqrt(e3-x.^2)./e3;
p=k2.*d2;
m111=cosd(p);
m112=-1i.*sind(p)./q2;
m121=-1i*q2.*sind(p);
m122=cosd(p);
Mtot=zeros(1,length(theta));
for j=1:length(theta)
M1=[m111(1,j),m112(1,j);m121(1,j),m122(1,j)];
Mtot=M1;
R(j) =((Mtot(1,1) +Mtot(1,2).*q3).*q1-Mtot(2,1) -Mtot(2,2).*q3)/(((Mtot(1,1) +Mtot(1,2).*q3).*q1+Mtot(2,1) +Mtot(2,2).*q3)).^2;
end
figure(1);
plot(theta,abs(R));
xlabel('incident angle');
ylabel('transmmission, s-pol');
plot is not showing any value error
Vectors must be the same length. pl help to plot

7 件のコメント

shiv gaur
shiv gaur 2022 年 1 月 27 日
pl any one correct the program
Torsten
Torsten 2022 年 1 月 27 日
The program might plot something if instead of R(j) you write R{j} and if you substitute the division sign "/" in the expression on the right-hand side by "./" and if you only try plot(theta,abs(R{1})). But I doubt this is what you expect to plot.
shiv gaur
shiv gaur 2022 年 1 月 27 日
blank
shiv gaur
shiv gaur 2022 年 1 月 27 日
blank plot is showing
Torsten
Torsten 2022 年 1 月 27 日
編集済み: Torsten 2022 年 1 月 27 日
Any error message ?
Any output to console if you remove the ; after the line
R{j} = ...;
?
shiv gaur
shiv gaur 2022 年 1 月 27 日
編集済み: Rik 2022 年 1 月 27 日
without looping graph look like that but not rigt value of r is not greater than one file att
theta=40:80;
lambda=633;
k0=2*pi/lambda;
e1=1.50^2;e3=1.33^2;e2=(0.12+1i*3.5)^2;
n1=1.50;n3=1.33;n2=0.12+1i*3.433;
d2=50;
n1=1.50;
x=n1*sind(theta);
k1=k0.*sqrt(e1.*mu1-x.^2);
Unrecognized function or variable 'mu1'.
k2=k0.*sqrt(e2.*mu2-x.^2);
k3=k0.*sqrt(e3.*mu3-x.^2);
q1=sqrt(e1-x.^2)./e1;
q2=sqrt(e2-x.^2)./e2;
q3=sqrt(e3-x.^2)./e3;
p=k2.*d2;
m111=cosd(p);
m112=-1i.*sind(p)./q2;
m121=-1i*q2.*sind(p);
m122=cosd(p);
disp(m111)
%5Mtot=zeros(length(theta));
%R=zeros(length(theta));
%for j=1:length(theta)
%M1=[m111(1,j),m112(1,j);m121(1,j),m122(1,j)];
%Mtot=M1;
R=((m111 +m112.*q3).*q1-m121 -m122.*q3)./(((m111 +m112.*q3).*q1+m121 +m122.*q3)).^2;
%end
%R(j) =((Mtot(1,1) +Mtot(1,2).*q3).*q1-Mtot(2,1) -Mtot(2,2).*q3)/(((Mtot(1,1) +Mtot(1,2).*q3).*q1+Mtot(2,1) +Mtot(2,2).*q3)).^2;
%end
figure(1);
plot(theta,abs(R));
xlabel('incident angle');
ylabel('transmmission, s-pol');
but using loop there is problem pl help
Rik
Rik 2022 年 1 月 27 日
Have a read here and here. It will greatly improve your chances of getting an answer.
Please try to avoid duplicate posts.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 1 月 27 日

0 投票

Is it possible that you ran this code twice with more theta values the first time? You are not preallocating R so if you ran multiple times R would exist with the previous size.
It would be a good idea to preallocate R in your code.

14 件のコメント

shiv gaur
shiv gaur 2022 年 1 月 27 日
how prelocate in this program pl help
shiv gaur
shiv gaur 2022 年 1 月 27 日
prelocate out side loop or inside loop pl help to write
shiv gaur
shiv gaur 2022 年 1 月 27 日
help to plot the graph
Torsten
Torsten 2022 年 1 月 27 日
You set
R(j) = something
in your code.
This will produce an error because "something" is not a single value, but either a vector or undefined.
I can't test it at the moment, but maybe you can try size(something).
shiv gaur
shiv gaur 2022 年 1 月 27 日
if we write R(j)=zeros(length(theta)); out side loop or inside
shiv gaur
shiv gaur 2022 年 1 月 27 日
in this program what the value of R(j) set pl
Torsten
Torsten 2022 年 1 月 27 日
What does size(something) reveal ?
shiv gaur
shiv gaur 2022 年 1 月 27 日
size of R is equal to R=zeros(length(theta));
Torsten
Torsten 2022 年 1 月 27 日
I did not mean size(R), but size(((Mtot(1,1)+Mtot(1,2).*q3).*q1 ...)
shiv gaur
shiv gaur 2022 年 1 月 27 日
size of M=zeros(1,length(theta));
Torsten
Torsten 2022 年 1 月 27 日
What is M ?
Can't you just add the line
size(expression)
in the for loop and tell me what Matlab prints to console ?
shiv gaur
shiv gaur 2022 年 1 月 27 日
heta=30:0.01:50;
lambda=633;
k0=2*pi/lambda;
e1=1.50^2;e3=1.33^2;e2=(0.12+1i*3.5)^2;
n1=1.50;n3=1.33;n2=0.12+1i*3.433;
d2=50;
n1=1.50;
x=n1*sind(theta);
k1=k0.*sqrt(e1.*mu1-x.^2);
k2=k0.*sqrt(e2.*mu2-x.^2);
k3=k0.*sqrt(e3.*mu3-x.^2);
q1=sqrt(e1-x.^2)./e1;
q2=sqrt(e2-x.^2)./e2;
q3=sqrt(e3-x.^2)./e3;
p=k2.*d2;
m111=cosd(p);
m112=-1i.*sind(p)./q2;
m121=-1i*q2.*sind(p);
m122=cosd(p);
Mtot=zeros(2,length(theta));
R=zeros(2,length(theta));
for j=1:length(theta)
M1=[m111(1,j),m112(1,j);m121(1,j),m122(1,j)];
Mtot=M1;
R(j) =((Mtot(1,1) +Mtot(1,2).*q3).*q1-Mtot(2,1) -Mtot(2,2).*q3)/(((Mtot(1,1) +Mtot(1,2).*q3).*q1+Mtot(2,1) +Mtot(2,2).*q3)).^2;
end
figure(1);
plot(theta,abs(R));
xlabel('incident angle');
ylabel('transmmission, s-pol');
pl help to plot
shiv gaur
shiv gaur 2022 年 1 月 27 日
whre to write the prelocation pl correct the code
shiv gaur
shiv gaur 2022 年 1 月 27 日
not giving right value

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

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

リリース

R2021b

タグ

質問済み:

2022 年 1 月 27 日

コメント済み:

Rik
2022 年 1 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by