0

Even when A is, say, 2 by 3 matrix, we have

A = [2 3 ; 1 6]

A(2) = 1

But if I really meant to get 1, I would have done

A(2,1)

So, if I am doing A(2) instead of A(2,1) most likely I am just making a mistake in my coding.

So, when A is a matrix, which is not just a vector, and when I did A(2), can I make Matlab to print warnings and pause, and not just assume I meant A(2,1) ?

user42459
  • 883
  • 3
  • 12
  • 29
  • 1
    No. Both are equally valid and supported [types of indexing](http://stackoverflow.com/a/32379806/3121310) for arrays. But there may be ways using functions and custom classes to effect this behavior. – TroyHaskin May 15 '16 at 05:42
  • MATLAB is a colum-major language (https://en.wikipedia.org/wiki/Row-major_order#Explanation_and_example), so you can apply vector-indexing with one index to a matrix. See this: http://stackoverflow.com/a/21413441/701049 I think this explains it really good on how the arrays are managed in the memory (`A(:)` yielding a vector) – tim May 15 '16 at 07:45

0 Answers0