フィルターのクリア

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 日間)
Ashmika Gupta
Ashmika Gupta 2021 年 7 月 20 日
回答済み: DGM 2021 年 7 月 20 日
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 Center および File ExchangeLoops 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