How can I sum up two indices to then change the value of the sums that are even?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Valeria Chacon
el 19 de Nov. de 2016
Respondida: Jan
el 19 de Nov. de 2016
theta=zeros(N,N);
index=(mod(theta,2)==0)
N in this case is any number inputed by the user. N is the dimensions of a matrix. So if the user inputed 2 then it would be [0,0 ; 0,0] how ever i need to make the sum of every 2 indices that is even to equal to 1. So the sum would be 1+1, 2+1, 2+1, and 2+2 and the result that I'm looking for is [1,0 ; 0,1]. Is there any way I can sum two indices to then change their value?
0 comentarios
Respuesta aceptada
Jan
el 19 de Nov. de 2016
In Matlab 2016b with automatic expanding:
theta = (1:N) + (1:N).'
And in former versions:
theta = bsxfun(@plus, (1:N), (1:N).')
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!