why if statement does not work
古いコメントを表示
I have a long code but for this part, I am getting errors. I did for loop and then insert an if statement that includes three conditions, but when running my code, it applies the last conditions for all
if i == 1 && i == 4 %inclined
Kl(1:3,1:3) = HAB*kBAI*HAB'; % kAA
Kl(4:6,1:3) = -kBAI*HAB' ; % kBA
Kl(1:3,4:6) = -HAB*kBAI ; % kAB
Kl(4:6,4:6) = kBAI ; % kBB
KG(1:3,1:3) = lA*Kl(1:3,1:3)*lA' ; % KAA
KG(4:6,1:3) = lB*Kl(4:6,1:3)*lA' ; % KBA
KG(1:3,4:6) = lA*Kl(1:3,4:6)*lB' ; % KAB
KG(4:6,4:6) = lB*Kl(4:6,4:6)*lB' ; % KBB
elseif i == 2 && i == 3 % for curved members
Kl(1:3,1:3) = TAB*kB_curved*TAB'; % kAA
Kl(4:6,1:3) = -kB_curved*TAB'; % kBA
Kl(1:3,4:6) = -TAB*kB_curved ; % kAB
Kl(4:6,4:6) = kB_curved ; % kBB
KG(1:3,1:3) = lA*Kl(1:3,1:3)*lA'; % KAA
KG(4:6,1:3) = lB*Kl(4:6,1:3)*lA' ; % KBA
KG(1:3,4:6) = lA*Kl(1:3,4:6)*lB' ; % KAB
KG(4:6,4:6) = lB*Kl(4:6,4:6)*lB' ; % KBB
else i == 5 && i == 6 % for all straight members
Kl(1:3,1:3) = HAB*kB_straight*HAB' % kAA
Kl(4:6,1:3) = -kB_straight*HAB'; % kBA
Kl(1:3,4:6) = -HAB*kB_straight ; % kAB
Kl(4:6,4:6) = kB_straight ; % kBB
KG(1:3,1:3) = lA*Kl(1:3,1:3)*lA' ; % KAA
KG(4:6,1:3) = lB*Kl(4:6,1:3)*lA' ; % KBA
KG(1:3,4:6) = lA*Kl(1:3,4:6)*lB' ; % KAB
KG(4:6,4:6) = lB*Kl(4:6,4:6)*lB' ; % KBB
end
回答 (1 件)
Walter Roberson
2022 年 3 月 22 日
編集済み: Walter Roberson
2022 年 3 月 22 日
if i == 1 && i == 4 %inclined
There is no value of i such that it is simultaneously true that i equals 1 and i equals 4.
You probably wanted the '||' operator
カテゴリ
ヘルプ センター および File Exchange で App Building についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!