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