0

I'm new for Matlab, and there is a question confusing me.

if A is a matrix that, A = [4 2; 2 3; 3 4]

what A(1) means?

A(1) = 4
A(2) = 2
A(3) = 3
A(4) = 2
A(5) = 3
A(6) = 4

and A(7) get an error: Index exceeds the number of array elements (6).

Wondering if A(1) means the 1st element, then why A(3) and A(4) not in the correct order?

thanks!

Kate Wang
  • 1
  • 1
  • 1
    They are in the correct order, MATLAB is column-major. You can read it in the docs: https://uk.mathworks.com/help/matlab/math/array-indexing.html#MatrixIndexingExample-2 – Ander Biguri Aug 18 '20 at 13:46
  • As to your title, what `A(1)` means can be found in the first duplicate, this is called *linear indexing*. As to the actual question, "are `A(3)` and `A(4)` swapped?", that boils down to understanding row major vs column major. See the second duplicate for that, or the link @AnderBiguri provided. – Adriaan Aug 18 '20 at 13:51
  • Thanks both of you: Ander Biguri and Adriaan :-) – Kate Wang Aug 18 '20 at 14:08

0 Answers0