How can I sum up two indices to then change the value of the sums that are even?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Jan
2016-11-19
In Matlab 2016b with automatic expanding:
theta = (1:N) + (1:N).'
And in former versions:
theta = bsxfun(@plus, (1:N), (1:N).')
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!