Filter löschen
Filter löschen

How can I sum up two indices to then change the value of the sums that are even?

2 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Jan
Jan am 19 Nov. 2016
In Matlab 2016b with automatic expanding:
theta = (1:N) + (1:N).'
And in former versions:
theta = bsxfun(@plus, (1:N), (1:N).')

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by