2

In GNU Octave, I can use the following code to get every 5th row of X.

How do I get another matrix X_2 that consists of the rows that have not been extracted or left behind in X?

X = [1;2;3;4;5;6;7;8;9;10;11]
ix = ( 5 : 5 : size(X,1) )
X_1 = X( ix , : )

I want X_2 to have everything but 5 and 10. Is this possible?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
babelproofreader
  • 530
  • 1
  • 6
  • 20

1 Answers1

4

Gnu Octave, Get every nth row of a matrix/vector:

X = [1;2;3;4;5;6;7;8;9;10;11]
ix = ( 5 : 5 : size(X,1) )

prints:

ix =
    5   10

Now, remove rows from the original matrix which will give you a list of the rows not extracted.

Example, remove row 5 and 10 from X:

X([5,10],:) = []

Prints X with 5 and 10 missing:

X =

    1
    2
    3
    4
    6
    7
    8
    9
   11

So that proves concept. Use your ix variable to do it on the specified columns:

X(ix,:) = []

That will make X a list of the rows that have not been extracted. If you need to not disturb the original, make a copy of X and put it into another variable before you do this. Then assign X_2 = X;

Source:

Remove a column from a matrix in GNU Octave

Community
  • 1
  • 1
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335