Construct a permutation matrix from two vectors

조회 수: 8 (최근 30일)
Lama Hamadeh
Lama Hamadeh 2023년 3월 23일
편집: Bruno Luong 2023년 3월 23일
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.

채택된 답변

Matt J
Matt J 2023년 3월 23일
편집: Matt J 2023년 3월 23일
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

추가 답변 (1개)

Bruno Luong
Bruno Luong 2023년 3월 23일
편집: Bruno Luong 2023년 3월 23일
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

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by