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

3 Ansichten (letzte 30 Tage)
Aknur am 24 Apr. 2023
Kommentiert: Aknur am 28 Apr. 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);
Best regards, Aknur
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Sivapriya Srinivasan am 25 Apr. 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 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Aknur am 28 Apr. 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

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by