Borrar filtros
Borrar filtros

change even column values only

3 visualizaciones (últimos 30 días)
PK
PK el 29 de Sept. de 2016
Comentada: Thorsten el 29 de Sept. de 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?

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (1)

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

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by