フィルターのクリア

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
Lewis HC
Lewis HC 2022 年 12 月 6 日
Thak you dear friends!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by