필터 지우기
필터 지우기

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 CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by