Inserting missing rows in a matrix
1 view (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
KSSV
on 2 Nov 2016
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 Comments
More Answers (0)
See Also
Categories
Find more on Matrices and 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!