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

 采纳的回答

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

1 个评论

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

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

提问:

L
L
2017-11-13

评论:

L
L
2017-11-13

Community Treasure Hunt

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

Start Hunting!

Translated by