change even column values only

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

采纳的回答

Thorsten
Thorsten 2016-9-29
A = ones(20);
A(:,mod(1:20, 2) == 0) = -1;
  2 个评论
PK
PK 2016-9-29
good answer! I got the following method.... A = ones(20) A(:,2:2:end) = -1
Thorsten
Thorsten 2016-9-29
You method is even better!

请先登录,再进行评论。

更多回答(1 个)

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

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by