how can i convert 1xn to mxn matrix ?
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello i have a variable x[k] k=1,...100
that takes some random numbers as an input, so i have a 1x101 matrix.
How can i create a matrix 20x101 .I tried the repmat function that works but
all of the rows are the same number because this function copies everything
for the first row . How can i actually create 20x101 matrix and still have random numbers
to each row?
Thank you in advance.
댓글 수: 0
답변 (2개)
David Hill
2019년 10월 20일
Look at rand or randi functions. Depending on what range you want your randon numbers to be in, either function could be used.
x = randi(100,20,101);
Will give you a 20x101 matrix of randon numbers between 1 and 100.
댓글 수: 0
Walter Roberson
2019년 10월 20일
Use persistent variables in your function. The first 19 times the function is called, just store the 100 values passed in. The 20th time the function is called, store the 100 values and then process the 20 x 100 values to create your 20 x 101 matrix of output and return that.
댓글 수: 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!