0

Possible Duplicate:
Can someone explain this example of deleting elements from a matrix in MATLAB?

i have some trouble in matlab and please help me suppose we have this matrices

X =

16 2 13
5 11 8
9 7 12
4 14 1

i want to understand how this command delete elements from this matrices and what will be as a result

X(2:2:10) = []

thanks very much i add also result of this command

16 9 2 7 13 12 1

but it is unclear for me

Community
  • 1
  • 1
  • 1
    This is an *exact* duplicate right down to the example matrix: [Can someone explain this example of deleting elements from a matrix in MATLAB?](http://stackoverflow.com/questions/572021/can-someone-explain-this-example-of-deleting-elements-from-a-matrix-in-matlab) Where did this example come from, if you don't mind my asking? – gnovice Mar 28 '11 at 14:02

2 Answers2

1

When you supply just one index (2:2:10), Matlab treats is as in index into all of the entries ordered by each row, then by column. So you are removing the 2nd (row 2 column 1) entry, the 4th (row 4 column 1 entry), the 6th (row 2 column 2) entry, the 8th (row 4, column 2) entry and then the 10th (row 2 column 3) element.

To be super clear, if you say X(1:5) you'll get [16, 5, 9, 4, 2] back.

MatlabSorter
  • 1,290
  • 1
  • 11
  • 19
0

it will start from the 2 location and advances with increment 2 till 10 (2, 4, 6, 8, 10). And every time it deletes the element from the calculated location (2, 4, 6, 8, 10).

Sarfraz Ahmed
  • 1,349
  • 6
  • 23
  • 43
  • yes but 2 is row number or simple element's number?- –  Mar 28 '11 at 10:30
  • I did not confirm as I don't have access to my matlab at the time...I think it is the element position. you can check that by just writing X(2) and pressing enter. it will take u to the specified position in the matrix. – Sarfraz Ahmed Mar 29 '11 at 11:52