필터 지우기
필터 지우기

How can I make this matrix ?

조회 수: 1 (최근 30일)
Sourasis Chattopadhyay
Sourasis Chattopadhyay 2022년 12월 13일
댓글: Voss 2022년 12월 14일

채택된 답변

Voss
Voss 2022년 12월 13일
% your matrix:
i = 0; m = 1; j = 2; n = 3;
M = repmat([i i i m m j j j n n],4,1)
M = 4×10
0 0 0 1 1 2 2 2 3 3 0 0 0 1 1 2 2 2 3 3 0 0 0 1 1 2 2 2 3 3 0 0 0 1 1 2 2 2 3 3
% delete columns 4-5 and 9-10:
M(:,[4 5 9 10]) = []
M = 4×6
0 0 0 2 2 2 0 0 0 2 2 2 0 0 0 2 2 2 0 0 0 2 2 2
  댓글 수: 4
Sourasis Chattopadhyay
Sourasis Chattopadhyay 2022년 12월 14일
Because my matrix size is not fixed. But every time I need to delete two column after the equal number of column interval.
Voss
Voss 2022년 12월 14일
Suppose you want to delete columns 4, 9, 14, ... and columns 5, 10, 15, ...
M = reshape(1:100,4,[])
M = 4×25
1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 93 97 2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 3 7 11 15 19 23 27 31 35 39 43 47 51 55 59 63 67 71 75 79 83 87 91 95 99 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100
spacing = 5;
N_Cols = size(M,2);
col_to_delete = [4:spacing:N_Cols 5:spacing:N_Cols];
M(:,col_to_delete) = []
M = 4×15
1 5 9 21 25 29 41 45 49 61 65 69 81 85 89 2 6 10 22 26 30 42 46 50 62 66 70 82 86 90 3 7 11 23 27 31 43 47 51 63 67 71 83 87 91 4 8 12 24 28 32 44 48 52 64 68 72 84 88 92
No loop necessary.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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