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?

 Réponse acceptée

Thorsten
Thorsten le 29 Sep 2016

0 votes

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

2 commentaires

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

Connectez-vous pour commenter.

Plus de réponses (1)

PK
PK le 29 Sep 2016

0 votes

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by