I am working with a large number of matrices of varying dimensions and have many times typed in the wrong number of indexes when accessing a matrix but because of linear indexing no crash occurs. Is there a way to disable linear indexing?
Example:
aa = rand(2,3,4,5);
>> aa(1,2,3)
ans =
0.76211
>> aa(1,1,1,1,1)
ans =
0.43666
The above are perfectly legal MatLab command but are probably not what would most often be intended.
To get automatic feedback when I do type in a mistake I have made an accessor function that checks the size of the input matrix and the number of indexes; then returns the appropriate values or calls error(). The need for this is dumb.
I can not group the matrices by size. Being more careful has not reduced my error rate. Adding the matrix size to its variable name helped some but has not eliminated my making mistakes.
Is there a good solution I am missing?
PS. In many other cases I love linear indexing, working with N-dimensional matrices by a single index is great. But here it is causing much wasted time.
0 Comments
Sign in to comment.