Making all Elements in Matrix Even.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Shubham Rajesh Yadav
el 23 de Nov. de 2021
Respondida: KSSV
el 23 de Nov. de 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.
0 comentarios
Respuesta aceptada
Walter Roberson
el 23 de Nov. de 2021
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 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!