How can I keep on rejecting the value of input until the value inputted is greater than 0? Like how can they loop separately until the correct value is input?
1 view (last 30 days)
Show older comments
Youssef Barakat
on 6 May 2021
Commented: Youssef Barakat
on 6 May 2021
a=input('Please enter the X co-ordinate of the bottom left hand corner of the space: ');
dataX=a;
if dataX < 0
disp('An invalid value of x was entered');
else
disp('valid values of x co-ordinates were entered');
end
a=input('Please enter the Y co-ordinate of the bottom left hand corner of the space: ');
dataY=a;
if dataY < 0
disp('An invalid value of Y was entered');
else
disp('valid value of Y co-ordinate was entered');
end
0 Comments
Accepted Answer
Alan Stevens
on 6 May 2021
Something like:
dataX = -1;
dataY = -1;
while dataX<0
a=input('Please enter the X co-ordinate of the bottom left hand corner of the space: ');
dataX=a;
if dataX < 0
disp('An invalid value of x was entered');
else
disp('valid values of x co-ordinates were entered');
end
end
while dataY<0
a=input('Please enter the Y co-ordinate of the bottom left hand corner of the space: ');
dataY=a;
if dataY < 0
disp('An invalid value of Y was entered');
else
disp('valid value of Y co-ordinate was entered');
end
end
More Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!