フィルターのクリア

Making all Elements in Matrix Even.

1 回表示 (過去 30 日間)
Shubham Rajesh Yadav
Shubham Rajesh Yadav 2021 年 11 月 23 日
回答済み: KSSV 2021 年 11 月 23 日
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.

採用された回答

Walter Roberson
Walter Roberson 2021 年 11 月 23 日
a=[53, 59; 61, 87]
a = 2×2
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
b = 2×2
54 60 62 88

その他の回答 (1 件)

KSSV
KSSV 2021 年 11 月 23 日
a=[53, 59, 61, 87] ;
iwant = a+mod(a,2)
iwant = 1×4
54 60 62 88

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by