why if statement does not work
Afficher commentaires plus anciens
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
Réponses (1)
Walter Roberson
le 22 Mar 2022
Modifié(e) : Walter Roberson
le 22 Mar 2022
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
Catégories
En savoir plus sur App Building dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!