Inserting missing rows in a matrix

6 ビュー (過去 30 日間)
Mido
Mido 2016 年 11 月 2 日
回答済み: KSSV 2016 年 11 月 2 日
If I have a matrix like x = [1 1; 1 2; 2 1; 2 2; 2 3; 3 1; 3 2]
x =
1 1
1 2
2 1
2 2
2 3
3 1
3 2
For every number in the first column I want it to have numbers 1 2 3 in the second column. As it is shown, Number 1 in the first column have 1 and 2 but doesn't have 3. I want to write a code that create a row which will be the third row in this matrix that writes 1 in the first column and 3 in the second column of this matrix. Similarly, I want the code to do the same thing and insert a last row as 3 in the first column have values of 1 and 2 but there is no 3. So, it will create a last row of [3 1].
I appreciate your help.

採用された回答

KSSV
KSSV 2016 年 11 月 2 日
Why fill gaps? You can make new matrix obeying your conditions.
iwant = zeros(9,2) ;
iwant(:,2) = repmat([1 2 3],1,3);
k = repmat([1 2 3],3,1) ;
iwant(:,1) = k(:);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by