what are the indices of the middle element of a matrix

8 visualizaciones (últimos 30 días)
Write a function called zero_middlethat takes an n-by-mmatrix
as an input where both nand mare odd numbers (the function does not have
to check the input). The function returns the input matrix with its center
element zeroed out.

Respuesta aceptada

Walter Roberson
Walter Roberson el 1 de Dic. de 2018
hint: end/2+1/2
  4 comentarios
Weisz Thomas
Weisz Thomas el 3 de Dic. de 2018
i am still a begginer and i have tried to follow your hints but now i have removed the output argument from my function because i don't know what value to assign to it. this is how my function looks:
function zero_middle(h)
[r,c]=size(h);
for ii=1:r
for jj=1:c
if mod(r,2) && mod(c,2)
h(end/2+1/2)=0;
end
end
end
end
please help me perfect it.
Walter Roberson
Walter Roberson el 3 de Dic. de 2018
output is h
you do not need any loop or any tests.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by