I want to insert rows to matrix with condition

i have this matrix
D=[ 1 2 3 4 0 0
1 2 5 3 4 0
1 3 1 0 0 0
1 3 4 2 0 0
2 1 6 0 0 0
2 1 5 4 0 0
2 3 4 2 0 0
2 3 5 4 1 0
3 1 2 0 0 0
3 1 4 0 0 0 ]
i want to insert at each same raw ( same the 1&2 columns) for example
1 2 3 4 0 0
1 2 5 3 4 0
another raw (like 1&2 columns and 0 0 0 0)
1 2 0 0 0 0
for the matrix D become
D=[1 2 0 0 0 0
1 2 3 4 0 0
1 2 5 3 4 0
1 3 0 0 0 0
1 3 1 0 0 0
1 3 4 2 0 0
2 1 0 0 0 0
2 1 6 0 0 0
2 1 5 4 0 0
2 3 0 0 0 0
2 3 4 2 0 0
2 3 5 4 1 0
3 1 0 0 0 0
3 1 2 0 0 0
3 1 4 0 0 0 ]

2 Kommentare

José-Luis
José-Luis am 15 Jan. 2013
Is this homework?
no this is part of my project

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Weitere Antworten (1)

Image Analyst
Image Analyst am 15 Jan. 2013

0 Stimmen

Hint: You can get a submatrix like this:
subMatrix = fullMatrix(1:someRow, :);
subMatrix = fullMatrix(row1:row2, :);
subMatrix = fullMatrix(someRow:end, :); % End has a special meaning
(pick one), and you can concatenate matrices vertically like this:
tallMatrix = [shortMatrix1; shortMatrix2]; % Use as many as you want
They all have to have the same number of columns of course.

3 Kommentare

sorry i can not understand
i have
a=[1 2 0 0 0
1 3 0 0 0
2 1 0 0 0
3 1 0 0 0]
and
b=[1 2 1 0 0
1 2 5 4 0
1 3 2 4 0
1 3 3 2 4
2 1 5 0 0
2 1 4 2 0
3 1 2 3 0
3 1 5 4 1 ]
i want to insert the first row of a to first row of b and second row of a to 3rd row of b .....etc like the result at question.
You gave a and b, what should be the result?
Image Analyst
Image Analyst am 15 Jan. 2013
What do you mean "to first row of b"? Do you mean insert that row of a "before" or "after" the first row of b, or do you mean that you want the row should overwrite ( not "insert") that row of b?

Melden Sie sich an, um zu kommentieren.

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by