Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

1 次查看(过去 30 天)
When i try to run the code i am getting an error "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side".
Whats wrong? I did not understand.
Nx=50;
Ny=50;
Mx=20e-9;
My=20e-9;
x=linspace(-Mx/2,Mx/2,Nx);
y=linspace(-My/2,My/2,Ny);
[X,Y]=meshgrid(x,y);
Vb1=0.228;
Rx1=5e-9;
Ry1=5e-9;
alfa=0e-9; w=1E+12; T=2*pi/w;
for i=numel(x)
fx =@(t) x(i) + alfa.*sin(w.*t);
idx=@(t) (fx(t)./Rx1).^2 + (Y./Ry1).^2 < 1;
Vb = @(t) idx(t).*0 + (1-idx(t)).*Vb1;
V0(i) = (1/T).*integral(Vb,0,T,'ArrayValued',true);
end
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

回答(1 个)

Torsten
Torsten 2022-3-3
Nx=50;
Ny=50;
Mx=20e-9;
My=20e-9;
x=linspace(-Mx/2,Mx/2,Nx);
y=linspace(-My/2,My/2,Ny);
Vb1=0.228;
Rx1=5e-9;
Ry1=5e-9;
alfa=0e-9; w=1E+12; T=2*pi/w;
T = 1.0;
for i=numel(x)
for j = 1:numel(y)
fx =@(t) x(i) + alfa.*sin(w.*t);
idx=@(t) (fx(t)./Rx1).^2 + (y(j)/Ry1).^2 < 1;
Vb = @(t) idx(t).*0 + (1-idx(t)).*Vb1;
V0(i,j) = (1/T).*integral(Vb,0,T,'ArrayValued',true);
end
end
  5 个评论
Özgür Alaydin
Özgür Alaydin 2022-3-4
编辑:Özgür Alaydin 2022-3-4
Dear Torsten
As you suggest i checked the formula of Vb. To me, it is okey.
To check that first tried the function given below.
Nx=50;
Ny=50;
Mx=20e-9;
My=20e-9;
x=linspace(-Mx/2,Mx/2,Nx);
y=linspace(-My/2,My/2,Ny);
[X,Y]=meshgrid(x,y);
Vb1=0.228;
Rx1=5e-9;
Ry1=5e-9;
alfa=0e-9; w=1E+12; T=2*pi/w;
idx=(X/Rx1).^2 + (Y/Ry1).^2 < 1;
V0=(idx)*0 + (1-idx)*Vb1;
surf(x*1e9,y*1e9,V0)
I got the figure as i want. Then i tried updated function given below but i could not get the result.
Loop creates zero except last row as i wrote you earlier. The value of the last row is as desired but I could not figure out what is wrong.
Thanks for advance.
clear
Nx=50;
Ny=50;
Mx=20e-9;
My=20e-9;
x=linspace(-Mx/2,Mx/2,Nx);
y=linspace(-My/2,My/2,Ny);
Vb1=0.228;
Rx1=5e-9;
Ry1=5e-9;
alfa=0e-9; w=1E+12; T=2*pi/w;
T = 1.0;
for i=numel(x)
for j = 1:numel(y)
fx =@(t) x(i) + alfa.*sin(w.*t);
idx=@(t) (fx(t)./Rx1).^2 + (y(j)/Ry1).^2 < 1;
Vb = @(t) idx(t).*0 + (1-idx(t)).*Vb1;
V0(i,j) = (1/T).*integral(Vb,0,T,'ArrayValued',true);
end
end
surf(x*1e9,y*1e9,V0)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by