Akzeptierte Antwort

Voss
Voss am 13 Dez. 2022

0 Stimmen

% 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 Kommentare

Sourasis Chattopadhyay
Sourasis Chattopadhyay am 14 Dez. 2022
How can i mak it in a loop for (m*n) matrix?
Voss
Voss am 14 Dez. 2022
Why do you want to do that?
Sourasis Chattopadhyay
Sourasis Chattopadhyay am 14 Dez. 2022
Because my matrix size is not fixed. But every time I need to delete two column after the equal number of column interval.
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by