I want to create a random matrix?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Help me!
I want to create a random matrix HM (3,5), it satisfies the following conditions:
1. The value of HM is a nonnegative integer from 0 to 4.
2. The total value of the elements in a row is less than or equal to 5.
Thank you very much!
3 Kommentare
Akzeptierte Antwort
Amit
am 29 Dez. 2013
okay .. an approach would be rejection method .. be careful .. for extremely large matrix this will be a bad idea .. tmp1= randi([0 c],a*100,b); tmp1=tmp1(sum(tmp1,2)<=d); HM=tmp1(1:a,:);
6 Kommentare
Weitere Antworten (1)
Amit
am 29 Dez. 2013
write down all possible ways to get 3 or less than 3 using integers 0-4 like [1 0 0 0 0] [1 1 0 0 0] etc.... pick one of the matrix for each row (randomly) and then use randperm to reorder them.
13 Kommentare
Amit
am 29 Dez. 2013
does b, c and d have any correlation? like in the example case, you have b=c+1, d=c+1
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!