# If part of While loop not executing any functions

조회 수: 1(최근 30일)
Harrison Forlines 2021년 11월 28일
편집: VBBV 2021년 11월 28일
VR = input('Input value of rated voltage of (VR) of 3-phase induction motor being tested: ');
IR = input('Input value of rated current (IR) of 3-phase induction motor being tested: ');
Pact = input('Input value of active/real power (Pact), or press enter if N/A: ');
Pre = input('Input value of reactive power (Pre), or press enter if N/A: ');
Papp = input('Input value of apparent power (Papp), or press enter if N/A: ');
PF = input('Input value of power factor (PF), or press enter if N/A: ');
*All of the above input values were imputted except for Papp & PF which were just left blank for calulation in the while loop
*Pact & Pre are 1-column arrays respectivly
while PF == isempty(PF)
if all(Pact ~= isempty(Pact)) && and(Pre ~= isempty(Pre))
break
end
Papp = sqrt((Pact.^2)+(Pre.^2));
PF = Pact./Papp;
end
Pin = (VR).*(IR).*sqrt(3).*(PF);
But when I execute the loop the values for Pin, Papp, & PF are still shown in the workspace as [ ] and are empty. I've tried all sorts of different combinations does anyone know how i can fix this???

댓글을 달려면 로그인하십시오.

### 답변(1개)

VBBV 2021년 11월 28일
편집: VBBV 2021년 11월 28일
while PF == isempty(PF)
if all(Pact == isempty(Pact)) && and(Pre == isempty(Pre))
break
else
Papp = sqrt((Pact.^2)+(Pre.^2));
PF = Pact./Papp;
end % use an if-else combination
end
Pin = (VR).*(IR).*sqrt(3).*(PF);
Use an if-else combination. Also change the if condition which seems to be true and therefore executes break and exits the while loop

댓글을 달려면 로그인하십시오.

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by