How can I sum up two indices to then change the value of the sums that are even?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Jan
on 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).')
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!