change even column values only

I create 20*20 2D array of all ones. And then I want to change even columns to minus one. How can I change with builtin function?

 采纳的回答

A = ones(20);
A(:,mod(1:20, 2) == 0) = -1;

2 个评论

good answer! I got the following method.... A = ones(20) A(:,2:2:end) = -1
You method is even better!

请先登录,再进行评论。

更多回答(1 个)

PK
PK 2016-9-29

0 个投票

good answer! I got the following method.... A = ones(20) A(:,2:2:end) = -1

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by