필터 지우기
필터 지우기

Error: Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-41.

조회 수: 2 (최근 30일)
h=0:0.5:20
m=size(h,2)
E=0.01*10^9;
A=0.001;
n=6;
a=20;
r=20/(2.*sind(180/n));
Lab=a;
Lbc=a*(sind(38)/sind(30));
Lac=a*(sind(38+30)/sind(30));
U=zeros(1,m);
for i=1:m
phi=acosd(h/(a*(sind(38)/sind(30))));
lab=2.*r.*sind(180/n);
lbc=sqrt(h(1,i).^2-2.*r.^2*cosd(phi)+2.*r.^2);
lac=sqrt(h(1,i).^2-2.*r.^2*cosd(360/n+phi)+2.*r.^2);
eab=(lab-Lab)/Lab;
ebc=(lbc-Lbc)/Lbc;
eac=(lac-Lac)/Lac;
Ltotal=(Lab+Lbc+Lac);
U(1,i)=(1/(2.*Ltotal)).*(Lab.*eab.^2+Lbc.*ebc.^2+Lac.*eac.^2)
end
I am not sure why I am getting this error. I want all variables except for U to be reassigned in each for loop. Please advise.

답변 (1개)

DGM
DGM 2021년 7월 20일
It's unclear what your intentions are. If I assume you're trying to do this all elementwise WRT h, then you missed an index:
phi = acosd(h(i)/(a*(sind(38)/sind(30))));
... but if that's what you're trying to do, then you don't even need the loop at all anyway.
h=0:0.5:20;
m=size(h,2);
E=0.01*10^9;
A=0.001;
n=6;
a=20;
r=20/(2.*sind(180/n));
Lab=a;
Lbc=a*(sind(38)/sind(30));
Lac=a*(sind(38+30)/sind(30));
phi=acosd(h/(a*(sind(38)/sind(30))));
lab=2.*r.*sind(180/n);
lbc=sqrt(h.^2-2.*r.^2*cosd(phi)+2.*r.^2);
lac=sqrt(h.^2-2.*r.^2*cosd(360/n+phi)+2.*r.^2);
eab=(lab-Lab)/Lab;
ebc=(lbc-Lbc)/Lbc;
eac=(lac-Lac)/Lac;
Ltotal=(Lab+Lbc+Lac);
U=(1/(2.*Ltotal)).*(Lab.*eab.^2+Lbc.*ebc.^2+Lac.*eac.^2)
If instead, you're trying to calculate lac and lbc elementwise WRT h, and phi as a vector each time in the loop, then the result U cannot be a vector, but will need to be a mxm matrix.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by