How can I create a vector of 10 random numbers?
조회 수: 40 (최근 30일)
이전 댓글 표시
I am looking to create a vector of 20 random numbers and then use 10 othjer random numbers to replace 10 of the data points with NaN
댓글 수: 0
답변 (2개)
Kye Taylor
2012년 10월 22일
If you use an approach like
x = rand(20,1);
idx = randi(20,10,1);
x(idx) = NaN,
you may replace less than ten numbers since there may be repeated integers in idx.
If you need to replace exactly 10 numbers every single time, try
x = rand(20,1);
idx = randperm(20);
x(idx(1:10)) = NaN;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!