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.
1 次查看(过去 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.
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!