Making all Elements in Matrix Even.
조회 수: 1 (최근 30일)
이전 댓글 표시
I want o make all the elements in the Matrix even.
For eg.
if the matrix is a=[53, 59, 61, 87],
The output matrix b should be b=[54, 60, 62, 88].
I have tried this,
for l=1:length(a)
if mod(l,2)==1
l=l+1;
end
b=(:,l);
end
but it doesnt work.
Any help would be appreciated.
Thanks.
댓글 수: 0
채택된 답변
Walter Roberson
2021년 11월 23일
a=[53, 59; 61, 87]
b = a;
for l=1:numel(b)
if mod(b(l),2)==1
b(l)=b(l)+1;
end
end
b
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!