Hi! How I can write condition "If, else if" for repeated value of variable ?

2 vues (au cours des 30 derniers jours)
Aknur
Aknur le 24 Avr 2023
Commenté : Aknur le 28 Avr 2023
Hello! Kindly ask about variables and condition. I have two variables plane00, and plane01. In some cases they can be parallel, and if plane01 equal to 6 second time then statement will be another
How I can write condition if for repeated value of variable
plane01 equal to 6 second time, then calculate Phi = 180 - Phi0;
Before I use condidition if plane00 and plane01 are parallel each other, and if plane01 again == 6, then statement will another
I used this one
elseif all(ismember([plane00, plane01], parallel_planes(3,:)))
disp('Parallel 3rd row 5 and 6 plane');
PhiBar = -(180 + Phi0); %last
ThetaBar = (90 - Theta0);
Thank you in advance for your time and any advice
Best regards, Aknur

Réponse acceptée

Sivapriya Srinivasan
Sivapriya Srinivasan le 25 Avr 2023
Hello Aknur,
You can modify the code to modify the exiting elseif statement to include an additional check
if all(ismember([plane00, plane01], parallel_planes(3,:)))
if plane01 == 6
% calculate Phi as 180 - Phi0
Phi = 180 - Phi0;
disp('Parallel 3rd row 5 and 6 plane with plane01 = 6 seconds');
else
% calculate PhiBar as -(180 + Phi0)
PhiBar = -(180 + Phi0);
ThetaBar = 90 - Theta0;
disp('Parallel 3rd row 5 and 6 plane');
end
end
if statement checks if both plane00 and plane01 are parallel to the third row of the parallel_planes matrix
if plane01 equals to 6seonds then code calculates phi as 190minus phi0
if not then phiBar as –(180+phi0) and thetaBar as 90-theta0
finally code displays a message indicating whether plane01 was equal tro 6seconds or not
You may need to modify the code depending on your specific use case
Hope this helps!
  1 commentaire
Aknur
Aknur le 28 Avr 2023
Thank you for your help. Yes it works for only one time.
My question was how to make that if plane01 == 6 second time, like in first iteration if plane01 == 6 % calculate Phi as 180 - Phi0 , but if plane01 == 6 again then accept Phi0 as another value of Phi0 (Phi(ii-1)) which were before

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by