필터 지우기
필터 지우기

how to feel an array with 3 numbers randomly

조회 수: 4 (최근 30일)
joy
joy 2014년 8월 14일
편집: Joakim Magnusson 2014년 8월 14일
Hi,
I have an array say A, now it could contain 10,20,30 and 40 elements. Now I want to fill this array with 90,105,120 numbers randomly.
i.e my array would contain 10/20/30/40 elements but each time it have to be filled up with only 90,105,120 values randomly

채택된 답변

Michael Haderlein
Michael Haderlein 2014년 8월 14일
Do I understand you correctly? In case of the 10 values array, you'd like to have e.g.
A=[90 120 105 105 120 90 90 90 120 105]
I'd go like this:
nums=[90 105 120];
A=nums(randi(3,1,10));
In case of 20 or more values, just change the third parameter in the randi function.
  댓글 수: 2
joy
joy 2014년 8월 14일
can u just tell me that what does the 2nd parameter 1 signifies in randi
Joakim Magnusson
Joakim Magnusson 2014년 8월 14일
편집: Joakim Magnusson 2014년 8월 14일
If you write
A=nums(randi(3,2,10));
You get something like:
A=[90 120 105 105 120 90 90 90 120 105;105 120 90 105 120 90 105 90 120 105];
The 2nd parameter choose number of rows.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by