Generating matrix of all possible combination

1 view (last 30 days)
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
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.

Sign in to comment.

Answers (1)

KSSV
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)) ;
  1 Comment
pradeep nazareth
pradeep nazareth on 21 Dec 2021
It generating only 1 matrix of 10 x 2. I want to generate all combinations of such matrices with 10 x 2.

Sign in to comment.

Products


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!