Dimension mismatch error trying to build 2D array in loop
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
brian egenriether
el 15 de Mzo. de 2017
Comentada: Roger Stafford
el 15 de Mzo. de 2017
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 comentario
Roger Stafford
el 15 de Mzo. de 2017
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.)
Respuesta aceptada
Roger Stafford
el 15 de Mzo. de 2017
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 comentarios
Más respuestas (2)
brian egenriether
el 15 de Mzo. de 2017
Editada: brian egenriether
el 15 de Mzo. de 2017
0 comentarios
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

