Variables in a matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to generate a 60x6 matrix and have each column be assigned a variable and randomly generate a value for each space. For example the first column be one variable and have it generate a random number for each location in that column and second column do the same thing independent of the first. So far I have,
m=zeros(60,6);
F=m(1);
P=m(2);
T=m(3);
r=m(4);
t=m(5);
F=1000+rand(1)*99000;
P=100+rand(1)*900;
T=10+rand(1)*90;
r=.05+rand(1)*.04;
t=.0001+rand(1)*.0008
When I run this it doesn't generate a matrix and every number is the same.
댓글 수: 0
답변 (1개)
Yash Ubale
2018년 11월 13일
Hello,
The problem here is that, you are storing the columns of matrix 'm' into different variables and then making changes to those variables and not the original matrix 'm' in a way that they store only one single value. Instead, you can try executing the following code :
m = zeros(60,6);
m(:,1) = rand(60,1)*99000 + 1000;
m(:,2) = rand(60,1)*900 + 100;
m(:,3) = rand(60,1)*90 + 10;
m(:,4) = rand(60,1)*0.04 + 0.05;
m(:,5) = rand(60,1)*0.0008 + 0.0001;
'rand(m,n)' generates a randomely generated matrix of size m x n. The numbers are between 0 and 1 which are drawn from a uniform distribution.
'rand(1)' will generate only one random number and not an entire column.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!