ELEMENTS IN ODD COLUMNS AND ROWS

1 visualización (últimos 30 días)
Lewis HC
Lewis HC el 6 de Dic. de 2022
Comentada: Lewis HC el 6 de Dic. de 2022
Hello dear friends, I ask you for help with this exercise:
Develop a function called imp_index that takes an array M as input argument and returns an array containing the elements of M that are in the odd columns and rows.
Thanks for your help
So far I have developed this code:
function out = imp_index(M)
M=A(1:2:end,1:2:end);
M=A(1:2:end,2:2:end);
M=A(2:2:end,1:2:end);
M=A(2:2:end,2:2:end);
end

Respuestas (1)

David Hill
David Hill el 6 de Dic. de 2022
M=randi(100,10)
M = 10×10
4 42 79 1 3 25 12 90 32 49 35 50 17 59 36 89 15 16 35 29 3 38 94 79 26 20 91 95 38 100 67 73 62 23 13 61 8 75 44 59 58 3 33 40 95 27 15 45 67 8 12 19 38 61 78 79 19 46 68 96 74 63 81 47 97 58 100 64 73 18 55 12 86 9 90 20 96 46 88 64 97 70 59 91 76 91 65 9 24 64 58 57 19 99 78 87 9 45 5 100
out=imp_index(M)
out = 1×25
4 3 58 74 97 79 94 33 81 59 3 26 95 97 76 12 91 15 100 65 32 38 67 73 24
function out = imp_index(M)
out=M(1:2:end,1:2:end);
out=out(:)';
end
  4 comentarios
Walter Roberson
Walter Roberson el 6 de Dic. de 2022
Remove the out=out(:)'; to get a matrix output
Lewis HC
Lewis HC el 6 de Dic. de 2022
Thak you dear friends!

Iniciar sesión para comentar.

Categorías

Más información sobre Logical 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!

Translated by