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?

 採用された回答

Thorsten
Thorsten 2016 年 9 月 29 日

0 投票

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 日

0 投票

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

カテゴリ

タグ

質問済み:

PK
2016 年 9 月 29 日

コメント済み:

2016 年 9 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by