How to replace range in matrix with specific value?

Hi,
I have for example a matrix:
A= [1 2 3; 2 3 4, 4 5 6]
1 2 3
2 3 4
4 5 6
how do I replace all values in col 1 and 2 to 5 so it would be
5 5 3
5 5 4
5 5 6
Thanks

 採用された回答

DGM
DGM 2023 年 5 月 18 日

0 投票

You can do that like so:
A = [1 2 3; 2 3 4; 4 5 6];
A(:,1:2) = 5
A = 3×3
5 5 3 5 5 4 5 5 6

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNumeric Types についてさらに検索

タグ

質問済み:

2023 年 5 月 18 日

コメント済み:

2023 年 5 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by