How to replace a row in a matrix using colon notation with another row

How do i replace a row in a matrix with another row using colon notation?
Matrix=[1,1,1;2,2,2;3,3,3;4,4,4]
Matrix = 4×3
1 1 1 2 2 2 3 3 3 4 4 4
ReplaceRow=[0,0,0]
ReplaceRow = 1×3
0 0 0
end result matrix would be
desired = [0,0,0;2,2,2;3,3,3;4,4,4]
desired = 4×3
0 0 0 2 2 2 3 3 3 4 4 4

 採用された回答

Walter Roberson
Walter Roberson 2022 年 8 月 30 日
Matrix=[1,1,1;2,2,2;3,3,3;4,4,4]
Matrix = 4×3
1 1 1 2 2 2 3 3 3 4 4 4
ReplaceRow=[0,0,0]
ReplaceRow = 1×3
0 0 0
desired = Matrix;
desired(1,:) = ReplaceRow
desired = 4×3
0 0 0 2 2 2 3 3 3 4 4 4

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by