positive numbers using while loop

hello, how do i make the user enter only positive number in an array using while loop to check positivity? thanks

 Accepted Answer

ready = false;
while ~ready
d = input('Please input a positive number: ');
ready = (d > 0);
end

1 Comment

When i tested this code, i wrote a matrix of 2 negative numbers and one postive but it accepted the matrix.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

L
L
on 13 Nov 2017

Commented:

L
L
on 13 Nov 2017

Community Treasure Hunt

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

Start Hunting!