Z must be a matrix, not a scalar or vector error while using surf function.

1 次查看(过去 30 天)
'Mtotal' should be calculated for 'a' and 'wd' each with 5values. Means 'Mtotal' should be a 5X5 matrix. But the loops comes to an end for single value of 'a' and 'wd' so am getting a single value for 'Mtotal' instead of getting a 5x5 matrix. Please correct me where I went wrong.
CODE:
clear all;
close all;
x=0
y=0
u0=4*pi*(10^-7);
f=5*10^6;
w=2*pi*f;
u=4*pi*(10^-7);
U=2;
N=5
Li=zeros(1,N)
L0=zeros(5,5)
M=zeros(1,N*N)
Mt1=zeros(5,5)
Mtotal=zeros(5,5)
a=0.1:0.05:0.3
for i=1:5
wd=0.007:0.001:0.011
for j=1:5
r0=[0.0004066 0.0003224 0.0002557 0.0002028 0.0001608]
d=1
s=0.001
e=7*(8.854*10^-12)
sig=0.11
alpha=3.9*10^-3
T=26
T0=33
dout=2.*a(i)
d1=sqrt(2).*a(i)
aw=wd(j)./2
din=dout-(2.*N.*wd(j))-(2.*(N-2).*s)
davg=(dout-din)./(dout+din)
ltc=4.*N.*(dout-(N-1).*(wd(j)+s))
Aw=pi.*(aw.^2)
R=(r0.*ltc.*(1+alpha.*(T-T0)))./Aw
theta=90
J=2.*sin(theta).*sin(theta)+cos(theta).*cos(theta)
sd=(w.*(sqrt((u.*e./2).*(sqrt(1+(sig./(w.*e)).^2)-1)))).^(-1)
G=exp(-d/sd)
Li=zeros(1,N)
ai=a(i)-2.*(N-1).*wd(j)-2.*(N-1).*s:2.*(wd(j)+s):a(i)-2.*(N-N).*wd(j)-2.*(N-N).*s
for k = 1:N
Ni=(u0./pi).*((ai(k).*log((2.*ai(k).*ai(k))./(ai(k)+d1)))+(ai(k).*log((2.*ai(k).*ai(k))./(ai(k)+d1)))+(2.*(d1-ai(k)-ai(k))))
Gi=((u0.*ltc)./(2.*pi)).*(log(aw)-0.12)
Li(k)=Ni-Gi
L0(i,j)=sum(Li)
end
r1=@(bi,bj) sqrt((x+bi).^2+(y+bj).^2+d.^2)
r2=@(bi,bj) sqrt((bi-x).^2+(y+bj).^2+d.^2)
r3=@(bi,bj) sqrt((bi-x).^2+(y-bj).^2+d.^2)
r4=@(bi,bj) sqrt((x+bi).^2+(y-bj).^2+d.^2)
C1=@(bi) bi+x
C4=@(bi) -bi-x
C2=@(bi) bi-x
C3=@(bi) -bi+x
d1=@(bj) y+bj
d2=@(bj) y+bj
d3=@(bj) y-bj
d4=@(bj) y-bj
Bz= @(bi,bj) ((u0./(4.*pi)).*((((((-1).^1).*d1(bj))./(r1(bi,bj).*(r1(bi,bj)+((-1).^(1+1)).*C1(bi))))-(C1(bi)./(r1(bi,bj).*(r1(bi,bj)+d1(bj)))))+(((((-1).^2).*d2(bj))./(r2(bi,bj).*(r2(bi,bj)+(((-1).^(2+1))).*C2(bi))))-(C2(bi)./(r2(bi,bj).*(r2(bi,bj)+d2(bj)))))+(((((-1).^3).*d3(bj))./(r3(bi,bj).*(r3(bi,bj)+(((-1).^(3+1))).*C3(bi))))-(C3(bi)./(r3(bi,bj).*(r3(bi,bj)+d3(bj)))))+(((((-1).^4).*d4(bj))./(r4(bi,bj).*(r4(bi,bj)+((-1).^(4+1)).*C4(bi))))-(C4(bi)./(r4(bi,bj).*(r4(bi,bj)+d4(bj)))))))
bi=a(i)-2.*(N-1).*wd(j)-2.*(N-1).*s:2.*(wd(j)+s):a(i)-2.*(N-N).*wd(j)-2.*(N-N).*s
for l=1:N
bj=a(i)-2.*(N-1).*wd(j)-2.*(N-1).*s:2.*(wd(j)+s):a(i)-2.*(N-N).*wd(j)-2.*(N-N).*s
for m=1:N
M(l,m)=integral2(Bz,0,bi(l),0,bj(m))
Mt1=sum(M(l,m))
Mtotal=(Mt1(l,m)).*J.*G
surf(a(i),wd(j),Mtotal(l,m));
end
end
end
end
ERROR:
Error using surf (line 71)
Z must be a matrix, not a scalar or vector.
Error in FPSSCopti3DM2 (line 116)
surf(a(i),wd(j),Mtotal(l,m));
  2 个评论
Swathi S
Swathi S 2019-8-21
Sir, that did not work. 'Mt1' should be a 5x5 matrix which will make 'Mtotal' also 5x5, thus the matrix of the inputs and output will eventually match. The problem is the loop comes to an end for a single set of value execuation (a and wd) not for 5 set values. Thats why only one value is returned in 'Mt1' which is causing the error. I dont know why the loop is not executed fully instead it stops after 1 set of values. Can you help me rectify?

请先登录,再进行评论。

回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-8-21
clc;
clear all;
close all;
x=0
y=0
u0=4*pi*(10^-7);
f=5*10^6;
w=2*pi*f;
u=4*pi*(10^-7);
U=2;
N=5
Li=zeros(1,N)
L0=zeros(5,5)
M=zeros(1,N*N)
Mt1=zeros(5,5)
Mtotal=zeros(5,5)
a=0.1:0.05:0.3
for i=1:5
wd=0.007:0.001:0.011
for j=1:5
r0=[0.0004066 0.0003224 0.0002557 0.0002028 0.0001608]
d=1
s=0.001
e=7*(8.854*10^-12)
sig=0.11
alpha=3.9*10^-3
T=26
T0=33
dout=2.*a(i)
d1=sqrt(2).*a(i)
aw=wd(j)./2
din=dout-(2.*N.*wd(j))-(2.*(N-2).*s)
davg=(dout-din)./(dout+din)
ltc=4.*N.*(dout-(N-1).*(wd(j)+s))
Aw=pi.*(aw.^2)
R=(r0.*ltc.*(1+alpha.*(T-T0)))./Aw
theta=90
J=2.*sin(theta).*sin(theta)+cos(theta).*cos(theta)
sd=(w.*(sqrt((u.*e./2).*(sqrt(1+(sig./(w.*e)).^2)-1)))).^(-1)
G=exp(-d/sd)
Li=zeros(1,N)
ai=a(i)-2.*(N-1).*wd(j)-2.*(N-1).*s:2.*(wd(j)+s):a(i)-2.*(N-N).*wd(j)-2.*(N-N).*s
for k = 1:N
Ni=(u0./pi).*((ai(k).*log((2.*ai(k).*ai(k))./(ai(k)+d1)))+(ai(k).*log((2.*ai(k).*ai(k))./(ai(k)+d1)))+(2.*(d1-ai(k)-ai(k))))
Gi=((u0.*ltc)./(2.*pi)).*(log(aw)-0.12)
Li(k)=Ni-Gi
L0(i,j)=sum(Li)
end
r1=@(bi,bj) sqrt((x+bi).^2+(y+bj).^2+d.^2)
r2=@(bi,bj) sqrt((bi-x).^2+(y+bj).^2+d.^2)
r3=@(bi,bj) sqrt((bi-x).^2+(y-bj).^2+d.^2)
r4=@(bi,bj) sqrt((x+bi).^2+(y-bj).^2+d.^2)
C1=@(bi) bi+x
C4=@(bi) -bi-x
C2=@(bi) bi-x
C3=@(bi) -bi+x
d1=@(bj) y+bj
d2=@(bj) y+bj
d3=@(bj) y-bj
d4=@(bj) y-bj
Bz= @(bi,bj) ((u0./(4.*pi)).*((((((-1).^1).*d1(bj))./(r1(bi,bj).*(r1(bi,bj)+((-1).^(1+1)).*C1(bi))))-(C1(bi)./(r1(bi,bj).*(r1(bi,bj)+d1(bj)))))+(((((-1).^2).*d2(bj))./(r2(bi,bj).*(r2(bi,bj)+(((-1).^(2+1))).*C2(bi))))-(C2(bi)./(r2(bi,bj).*(r2(bi,bj)+d2(bj)))))+(((((-1).^3).*d3(bj))./(r3(bi,bj).*(r3(bi,bj)+(((-1).^(3+1))).*C3(bi))))-(C3(bi)./(r3(bi,bj).*(r3(bi,bj)+d3(bj)))))+(((((-1).^4).*d4(bj))./(r4(bi,bj).*(r4(bi,bj)+((-1).^(4+1)).*C4(bi))))-(C4(bi)./(r4(bi,bj).*(r4(bi,bj)+d4(bj)))))))
bi=a(i)-2.*(N-1).*wd(j)-2.*(N-1).*s:2.*(wd(j)+s):a(i)-2.*(N-N).*wd(j)-2.*(N-N).*s
for l=1:N
bj=a(i)-2.*(N-1).*wd(j)-2.*(N-1).*s:2.*(wd(j)+s):a(i)-2.*(N-N).*wd(j)-2.*(N-N).*s
for m=1:N
M(l,m)=integral2(Bz,0,bi(l),0,bj(m))
Mt1=sum(M(l,m))
Mtotal(k)=Mt1*J*G
%surf(a(i),wd(j),Mtotal(l,m));
end
end
end
end
surf(a,wd,Mtotal);
Still you have to correctify to get the correct results
yu.png

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by