Effacer les filtres
Effacer les filtres

change even column values only

3 vues (au cours des 30 derniers jours)
PK
PK le 29 Sep 2016
Commenté : Thorsten le 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?

Réponse acceptée

Thorsten
Thorsten le 29 Sep 2016
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
good answer! I got the following method.... A = ones(20) A(:,2:2:end) = -1

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by