I'm supposed make a vector called Vec that contains a 1x9 ranging from integers 1 through 9 in random order. There always tends to be a zero in the vector when the code is ran. How can I find the zeros and replace them with an integer from 1-9.
조회 수: 1 (최근 30일)
이전 댓글 표시
%I have this so far
Vec = rand(1,9)*9;
%I keep getting zeros in the vector when the code is ran. How can find the zero and replace with another integer from 1-9.
댓글 수: 0
채택된 답변
Star Strider
2016년 9월 14일
편집: Star Strider
2016년 9월 14일
I don’t get zeros when I run it, but then I don’t get integers. (I suspect you’re using fix or round to get the integers. You need to use ceil:
Vec = ceil(rand(1,9)*9);
Another function you might find useful is randi that by default produces random positive integers (unless you ask it to return random integers over a different range).
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!