Dimension mismatch error trying to build 2D array in loop
조회 수: 10 (최근 30일)
이전 댓글 표시
Hi, I am trying to build a matrix in a loop. Each row of the matrix should be a vector that describes a curve in in one variable (A) with the other (Co) held constant. The next loop should be the same vector as before but with Co advanced by one index. I need to then plot the final matrix with surf. I am getting a dimension mismatch when I try to write the vectors to one row (or column) of the matrix. Here is my code
clc
clear
eps0 = 8.854188e-12;
epsr = 11.2;
a = 1e-6:1e-6:20e-6; %half trace width
B =(6e-6)+a; %half trace + gap width
h = 1e-3; %dielectric substrate thickness
len=length(a);
co = linspace(80e-6,100e-6,len);
[A,Co] = meshgrid(a,co);
Z0=zeros(len);
for n=1:len
%==== C1 calculation =======================================
B =(6e-6)+A;
num3 = 1-(B./Co(n)).^2; %numerator for k3
den3= 1-(A./Co(n)).^2; %denominator for k3
k3 =(A./B).*sqrt(num3./den3);
k3_prime = (sqrt(1-(k3).^2)); %complimentary argument
C1 = 2*eps0*ellipke(k3)./ellipke(k3_prime);
%==== C2 calculation ========================================
num4 = 1-(sinh(pi*B/(2*h))).^2/(sinh(pi*Co(n)/(2*h))).^2;
den4 = 1-(sinh(pi*A/(2*h))).^2/(sinh(pi*Co(n)/(2*h))).^2;
k4 = (sinh(pi*A/(2*h))./sinh(pi*B/(2*h))).*sqrt(num4./den4);
k4_prime = (sqrt(1-(k4).^2)); %complimentary arguement
C2 = 2*eps0*(epsr-1)*ellipke(k4)./ellipke(k4_prime);
%==== Eps_re calculation ====================================
eps_re = 1+ C2./(2*C1);
%==== Z0 calculation ========================================
Z0(:,n) = 30*pi./(sqrt(eps_re)).*(ellipke(k3_prime)./ellipke(k3)); %This part broken
end
surf(A,Co,Z0);
Thanks in advance for any help, Brian
댓글 수: 1
Roger Stafford
2017년 3월 15일
I can’t tell how you indexed the rhs to get Z0(:,n), but if you did it in a similar manner to the way you indexed Co, you might be getting the wrong result. Co(n) gives you the equivalent of co(n) in this case because Co was the second output in meshgrid. However, if you write B(n), the result will always be the same, namely 6e-6+a(1), because A was the first output in meshgrid. To avoid confusion, you should always write Co(n,1) and B(1,n) if that is what you mean. (I am just guessing about your problem here since I don’t know the underlying theory.)
채택된 답변
Roger Stafford
2017년 3월 15일
I believe you will find that the right hand side of
Z0(:,n) = 30*pi./(sqrt(eps_re)).*(ellipke(k3_prime)./ellipke(k3));
is a 20-by-20 matrix while it is attempting to stuff it into a 20-element column vector space. It simply won’t fit!
댓글 수: 0
추가 답변 (2개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

