Sym Matrices can be Indexed with non-Logical/non-Integer. Bug?

2 views (last 30 days)
Linear indexing into a sym array:
A = sym([1 2;3 4])
A = 
A(.5)
Warning: Integer operands are required for colon operator when used as index.
ans = 
1
A(1.1)
Warning: Integer operands are required for colon operator when used as index.
ans = 
1
A([1.2 2.2])
Warning: Integer operands are required for colon operator when used as index.
ans = 
But element indexing produces an error
A(1.2,2.2)
Index in position 2 is invalid. Array indices must be positive integers or logical values.

Error in sym/subsref (line 909)
R_tilde = builtin('subsref',L_tilde,Idx);
But note that the error message is about the index in position 2. For a real array the error is the index in the first position.
I assume that this is a bug?
  2 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 1 Sep 2021
It seems to be happy to treat A as a 1-D array, or a 2-D array with rounding of the first-dimension index, as long as the second index is an integer. This is clearly a "feature".
Paul
Paul on 3 Sep 2021
Apparenty it is a "feature." I submitted to Tech Support and the response said a change in behavior has been submitted as an enhancement request. Seems like a bug to me.
I wonder if there are any other objects that have the same behavior as sym objects.

Sign in to comment.

Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!