Filter löschen
Filter löschen

change even column values only

1 Ansicht (letzte 30 Tage)
PK
PK am 29 Sep. 2016
Kommentiert: Thorsten am 29 Sep. 2016
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?

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

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

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by