Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab (size)

  1. Aug 10, 2009 #1


    User Avatar

    What does the function size(A,1) and size(A,2) and size(A,32) mean for a random (in other words, any) 2 by 2 matrix?
  2. jcsd
  3. Aug 10, 2009 #2
    size(A,n) returns the length along the nth dimension of the matrix A.

    This means that for a 2x2 matrix (i.e a 2D matrix) for n>2 we have that size(A,n)=1 but for n=1,2 size(A,n)=2 since it is only in the first two dimensions that the matrix has any entries.
  4. Aug 12, 2009 #3


    User Avatar

    What is the nth dimension of a matrix A? How is dimension defined?

    Isn't it the case that the dimension of a 2x2 matrix is 4?

    Or are you referring to that dimension 1 of a matrix is the number of rows. 2nd dimension of a matrix is the column size? But what is the 3rd dimension of a matrix?
    Last edited: Aug 12, 2009
  5. Aug 12, 2009 #4


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    In this context, the first "dimension" is the number of columns, and the second "dimension" is the number of rows.

    A 2x2 matrix can be thought of as a single entry in a 1-element long list of 2x2 matrices, which is why the higher "dimensions" in MATLAB all have length 1.

    - Warren
  6. Aug 13, 2009 #5


    User Avatar

    I think it's the opposite after trying it on a 3 by 2 matrix. First dimension is the number of rows and second dimension is the number of columns.

    However, it would make more sense if MATLAB gave 0 as the size of the higher dimensions of matrices.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook