ERROR : Unrecognized function or variable , Index exceeds the number of array elements
조회 수: 2 (최근 30일)
이전 댓글 표시
Graphs of parallel and vertical polarization of microwaves are being implemented as matlabs.
However, the error mentioned in the title occurred.
Please tell me how to solve this error.
er1 = 2.55;
er2 = 1;
eta_1 = 377;
eta_2 = 377/sqrt(er1);
sin(theta_b) = 1/sqrt(1+er1/er2);
cos(theta_t) = sqrt(1-er1*sin(theta_b)^2/er2);
for theta_i = [1:90];
parallel_pol = (eta_2*cos(theta_t)-eta_1*cos(theta_i))/(eta_2*cos(theta_t)+eta_1*cos(theta_i));
end
plot(theta_i,abs(parallel_pol),"-","r","LineWidth",2)
댓글 수: 0
채택된 답변
Voss
2022년 3월 16일
편집: Voss
2022년 3월 16일
This line:
sin(theta_b) = 1/sqrt(1+er1/er2);
is not valid syntax because you cannot assign a value to sin(theta_b). If you want to assign a value to theta_b such that the mathematical relation above is true, you could do this:
theta_b = asind(1/sqrt(1+er1/er2));
which is basically "solving for" theta_b in terms of the other variables, using the inverse sine function asind(), which returns an angle in degrees.
And since you're dealing with angles in degrees here, you should use sind and cosd, instead of sin and cos, which expect input angles to be in radians.
I made those changes and a few others below:
er1 = 2.55;
er2 = 1;
eta_1 = 377;
eta_2 = 377/sqrt(er1);
% sin(theta_b) = 1/sqrt(1+er1/er2);
% cos(theta_t) = sqrt(1-er1*sin(theta_b)^2/er2);
theta_b = asind(1/sqrt(1+er1/er2));
theta_t = acosd(sqrt(1-er1*sind(theta_b)^2/er2));
% for theta_i = [1:90];
% parallel_pol = (eta_2*cos(theta_t)-eta_1*cos(theta_i))/(eta_2*cos(theta_t)+eta_1*cos(theta_i));
% end
theta_i = 1:90;
parallel_pol = (eta_2*cosd(theta_t)-eta_1*cosd(theta_i))./(eta_2*cosd(theta_t)+eta_1*cosd(theta_i));
% plot(theta_i,abs(parallel_pol),"-","r","LineWidth",2)
plot(theta_i,abs(parallel_pol),"-r","LineWidth",2);
xlabel('theta_i');
ylabel('parallel\_pol');
댓글 수: 7
Voss
2022년 3월 16일
Check if you have any variables called sind, sin, acosd, or sqrt, because there is no indexing going on in that line, which is what the error is about, so it seems that some variable may have the same name as one of those functions. And maybe put a clear statement at the top of your script (I don't if that matters in a Live Script).
Also, note that I changed sin to sind in that line - it was an oversight in my original answer.
추가 답변 (2개)
David Hill
2022년 3월 16일
er1 = 2.55;
er2 = 1;
eta_1 = 377;
eta_2 = 377/sqrt(er1);
sin_theta_b = 1/sqrt(1+er1/er2);%just a scalar sin(theta_b) makes no sense
cos_theta_t = sqrt(1-er1*sin_theta_b^2/er2);%just scalar cos(theta_t) makes no sense
theta_i = 1:90;%no need for a loop (I assume this is in degrees)
parallel_pol = (eta_2*cos_theta_t-eta_1*cosd(theta_i))./(eta_2*cos_theta_t+eta_1*cosd(theta_i));%I assume you want cosd
plot(theta_i,abs(parallel_pol))
Enrico Gambini
2022년 3월 16일
Hi, try this.
er1 = 2.55;
er2 = 1;
eta_1 = 377;
eta_2 = 377/sqrt(er1);
sin_theta_b = 1/sqrt(1+er1/er2);
cos_theta_t = sqrt(1-er1*sin_theta_b^2/er2);
for i = [1:90];
parallel_pol(i) = (eta_2*cos_theta_t-eta_1*cos(i))/(eta_2*cos_theta_t+eta_1*cos(i));
end
plot([1:90],abs(parallel_pol),"r-","LineWidth",2);
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!