Indexed deletion with an empty index transforms a matrix into a row vector since R2016a

2 views (last 30 days)
When using indexed deletion on a matrix, this matrix is ALWAYS transformed into a row vector, independent if the empty index is an "1x0" empty double column OR row vector.
This behavior originated in R2016a and can be reproduced by the following commands:
>> A = rand(2)
A =
0.4218 0.7922
0.9157 0.9595
Create an empty index:
>> ind = 1:0
ind =
1×0 empty double row vector
Use logical indexing:
>> A(ind)
ans =
1×0 empty double row vector
Performing  indexed deletion using the the empty index creates a row-vector, even if the empty index is a column vector
>> A(ind) = []
A =
    0.4218    0.9157    0.7922    0.9595
>> A(transpose(ind)) = []
A =
    0.4218    0.9157    0.7922    0.9595
As a comparison, the output of the same commands in MATLAB R2015b looks like:
>> A = rand(2)
A =
0.8147 0.1270
0.9058 0.9134
>> A(1:0) = []
A =
0.8147 0.1270
0.9058 0.9134

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Jan 2018
This was a deliberate change for the MATLAB release R2016a, in order to get consistent behavior for deletion operations. When you do indexed deletion with a single, non-empty subscript, the matrix is always reshaped to a row vector.
>> B = rand(2)
B =
0.2785 0.9575
0.5469 0.9649
>> B(1) = []
B =
0.5469 0.9575 0.9649
In R2016a, this behavior was enforced for single empty subscripts as well. The shape of the empty index makes no difference for indexed deletion.

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!