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!