I need to remove randi from for loop
    조회 수: 1 (최근 30일)
  
       이전 댓글 표시
    
I need to remove randi from the for loop. Any help would appreciate.
     I=30;
     t1=randi([1 5],1,I);
     t2=randi([6 10],1,I);
    for i=1:I   
    TD(1,i)=randi([t1(1,i) t2(1,i)],1,1);
    end
댓글 수: 2
  Star Strider
      
      
 2018년 1월 28일
				That seems easy enough to do, although it would be interesting to know the reason you want to do it.
It would be best leave your code as it is, and simply overwrite ‘TD’ with something else.
채택된 답변
  Image Analyst
      
      
 2018년 1월 28일
        randi() takes a range of integers. Since you want that range to change every column, I don't see how there is a way to do it without a for loop. However, if the (badly-named) I is less than a million, the for loop will be fast (less than a second or so)
댓글 수: 0
추가 답변 (1개)
  Star Strider
      
      
 2018년 1월 28일
        The code you posted does exactly what you describe.
Try this instead of the loop if you simply want something different:
TD = randi(10, 1, I);
댓글 수: 0
참고 항목
카테고리
				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!


