Return first few values to zero in a row

Hi I would like to change only the first few values in a row to zero?
For example I have matrix A=[1 2 4 5 6 7 8 9 0 2 3 4 5 6]
If I want to make the first column until ninth column to be zero, the the new matrix B will be: B=[0 0 0 0 0 0 0 0 0 2 3 4 5 6].
If I want to make the first column until fourth column to be zero, the the new matrix B will be: B=[0 0 0 0 6 7 8 9 0 2 3 4 5 6].
I was thinking something like: A(1,:)=zeros(1,4) but it won't change to zero.
Thank you!

 採用された回答

Voss
Voss 2021 年 12 月 28 日

0 投票

A=[1 2 4 5 6 7 8 9 0 2 3 4 5 6]
A = 1×14
1 2 4 5 6 7 8 9 0 2 3 4 5 6
B1 = A;
B1(1:9) = 0
B1 = 1×14
0 0 0 0 0 0 0 0 0 2 3 4 5 6
B2 = A;
B2(1:4) = 0
B2 = 1×14
0 0 0 0 6 7 8 9 0 2 3 4 5 6

1 件のコメント

Hokkien
Hokkien 2021 年 12 月 28 日
Thank you so much!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 12 月 29 日

0 投票

@Hokkien you might want to review the short training to go over these basic indexing rules:

カテゴリ

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

質問済み:

2021 年 12 月 28 日

回答済み:

2021 年 12 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by