what does this code represents? and why rand() has no value between parentheses?
조회 수: 5 (최근 30일)
이전 댓글 표시
function [outcome]=customer
x=rand() ;
if x <= 0.2
outcome = 1 ;
else
outcome = 0;
end
댓글 수: 0
채택된 답변
추가 답변 (1개)
James Tursa
2019년 3월 22일
편집: James Tursa
2019년 3월 22일
rand() is the same as rand without the parentheses ... they both simply call the rand function with no input arguments. The behavior of rand is that when called with no input arguments, it returns a scalar.
This function code simply gets a random number between 0 and 1. If it is less than or equal to 0.2, the outcome is assigned a value of 1. Otherwise the outcome is assigned a value of 0. The value of outcome is returned by the function.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!