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!