开发者

Matrix Indexing Question in Matlab [duplicate]

This question already has a开发者_如何学JAVAnswers here: Closed 11 years ago.

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


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜