Generating matrix of all possible combination
1 view (last 30 days)
Show older comments
a = 100 : 100 : 1000;
b = 0.1 : 0.1 : 1;
Generate all combinations of matrix one by one containg 10 rows, each row contains 2 columns of 'a' and 'b'. like [100 0.1; 100 0.1; 100 0.1; 100 0.1; 100 0.1; 100 0.1; 100 0.1; 100 0.1; 100 0.1; 100 0.1 ], [100 0.1; 100 0.1; 100 0.1; 100 0.1; 100 0.1; 100 0.1; 100 0.1; 100 0.1; 100 0.1; 100 0.2 ], .....[1000 1; 1000 1 ; 1000 1; 1000 1; 1000 1 ; 1000 1; 1000 1; 1000 1 ; 1000 1; 1000 1 ].
Note: Hard coding of multiple for loops should be avoided.
1 Comment
Walter Roberson
on 21 Dec 2021
It is not clear to me why you have marked this as being related to the Vehicle Network Toolbox? The answers might be quite different if it is expected to use functions from Vehicle Network Toolbox.
Answers (1)
KSSV
on 21 Dec 2021
a = 100 : 100 : 1000;
b = 0.1 : 0.1 : 1;
iwant = zeros(10,2) ;
iwant(1:2:10,:) = a(randi(length(a),5,2)) ;
iwant(2:2:10,:) = b(randi(length(a),5,2)) ;
See Also
Categories
Find more on Automated Driving Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!