Effacer les filtres
Effacer les filtres

Making all Elements in Matrix Even.

1 vue (au cours des 30 derniers jours)
Shubham Rajesh Yadav
Shubham Rajesh Yadav le 23 Nov 2021
Réponse apportée : KSSV le 23 Nov 2021
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.

Réponse acceptée

Walter Roberson
Walter Roberson le 23 Nov 2021
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

Plus de réponses (1)

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

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by