Construct a permutation matrix from two vectors

9 views (last 30 days)
Hi,
If I have two vectors:
a = [1 ; 2 ; 3];
b = [4 ; 5 ; 6];
How can I constrcut a matrix that has the shape of:
Thanks.

Accepted Answer

Matt J
Matt J on 23 Mar 2023
Edited: Matt J on 23 Mar 2023
a = [1 ; 2 ; 3];
b = [4 ; 5 ; 6];
[B,A]=ndgrid(b,a);
c=[A(:),B(:)]
c = 9×2
1 4 1 5 1 6 2 4 2 5 2 6 3 4 3 5 3 6

More Answers (1)

Bruno Luong
Bruno Luong on 23 Mar 2023
Edited: Bruno Luong on 23 Mar 2023
combinations, new stock function in R2023a
a = [1 ; 2 ; 3];
b = [4 ; 5 ; 6];
combinations(a,b)
ans = 9×2 table
a b _ _ 1 4 1 5 1 6 2 4 2 5 2 6 3 4 3 5 3 6

Categories

Find more on Multidimensional Arrays 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!