I need to check user input to make sure it's a number. The first part of the while loop works if i input a number, but the 'else' part gets stuck on infinite loop if I input something else, and it won't go out even if I input a number.
%Part of a Program to calculate equivalent resistance for series and parallel circuits
n = input('Enter Number of resistors: ')for count = 1:n %input resistance values into an array
R(count) = input(['Enter the value of Resistor ' num2str(count) ': ']); flag = false; while ~flag num = isnumeric(R(count)); %check if resistance input is a number
if num == true %This part works and i can get through the whole for loop if I enter numbers correctly
flag = true; else %This part gets stuck on an infinite loop even if I enter a number
disp('incorrect entry'); R(count) = input(['Enter the value of Resistor ' num2str(count) ': ']); end end end
Best Answer