How to change values of elements in array at rows that meet a condition?

1 次查看(过去 30 天)
For example if I have array
A = [1;2;3;4;5;6;7;8]
and I want to change all values at rows that are divisible by 2 to 0 to produce
A = [1;0;3;0;5;0;7;0]
How would I accomplish this?

回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2015-6-26
A(mod(A,2)==0)=0

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by