ELEMENTS IN ODD COLUMNS AND ROWS

1 次查看(过去 30 天)
Lewis HC
Lewis HC 2022-12-6
评论: Lewis HC 2022-12-6
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

回答(1 个)

David Hill
David Hill 2022-12-6
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 个评论
Walter Roberson
Walter Roberson 2022-12-6
Remove the out=out(:)'; to get a matrix output

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by