Variables in a matrix
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Yash Ubale
on 13 Nov 2018
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 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!