How to generate a random number from a matris
조회 수: 1 (최근 30일)
이전 댓글 표시
%%we crate a matrix like this and we whant to generate a random number from matrix that made i dont know how!
Y=randi([0,300],[1,500];
댓글 수: 2
Rik
2023년 1월 6일
So you want to select a number at random from the array Y? Or do you simply want to generate some random number?
답변 (1개)
Rik
2023년 1월 6일
편집: Rik
2023년 1월 6일
If you want to select a number randomly from Y, you can use randi directly to index:
Y=randi([0,300],[1,500]);
RandomScalar=Y(randi(end))
This works because randi(imax) will generate a number between 1 and imax. The end keyword can be used to automatically determine the last position in the array.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!