Row/Column Deletion Formatting

3 ビュー (過去 30 日間)
Jonathan
Jonathan 2013 年 7 月 18 日
Though the title sounds quite trivial, I am confused as to how MATLAB formats the resulting matrix after a deletion.
For instance, in the MATLAB user guide they provide the following example:
You can delete rows and columns from a matrix by using a pair of square brackets. Start with
X =
16 4 2 13
5 7 11 8
9 3 7 12
4 21 13 1
To delete the second column of X, use
X(: , 2) = [ ]
X =
16 2 13
5 11 8
9 7 12
4 13 1
However, using a single subscript deletes a single element, or sequence of elements, and reshapes the remaining elements into a row vector. Therefore
X(2 : 2 : 10) = [ ]
X =
5 4 11 13 8
How am I sure that the row vector will be created if, say for instance, the sequence of elements that is deleted is an actual column. As an example,
A = magic( 3 )
A =
8 1 6
3 5 7
4 9 2
If I call the following,
A( min(A) ) = [ ]
A =
1 5 9 6 7 2
Though I would expect that, since it technically performs a deletion on the first column, the resulting matrix would be formatted as such
A =
1 6
5 7
9 2
Could someone within the community further explain this?

採用された回答

Cedric
Cedric 2013 年 7 月 19 日
編集済み: Cedric 2013 年 7 月 19 日
When you index A using one sub, you perform what is called a linear indexing (see e.g. IND2SUB or SUB2IND). When you do so, the outcome of the deletion is a row vector, because you perform an operation that breaks the structure of the array in fact. This behavior is Mathworks' choice, and they could have defined it as well as an illegal operation (incompatible with data structure).
  1 件のコメント
Jonathan
Jonathan 2013 年 7 月 19 日
I had figured it was due to linear indexing, but I just wanted to verify. Thanks for the clarification. I appreciate it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by