필터 지우기
필터 지우기

How to add parameters to randi inputs

조회 수: 2 (최근 30일)
Christian Armistead
Christian Armistead 2017년 12월 10일
답변: Roger Stafford 2017년 12월 10일
I need to use randi to produce a string of random numbers, the string should either end when the last digit of the last number is 9 or the the output reaches 15 numbers. Also the numbers can only be between 1 and 999. I know how to use the randi function however I don't know how to use it with all of these parameters.

답변 (1개)

Roger Stafford
Roger Stafford 2017년 12월 10일
v = randi(999,15,1);
for k = 1:15
if mod(v(k),10) == 9
v = v(1:k);
break;
end
end
% Vector v is the desired result

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by