Return first few values to zero in a row

1 次查看(过去 30 天)
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
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 个)

Image Analyst
Image Analyst 2021-12-29
@Hokkien you might want to review the short training to go over these basic indexing rules:

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by